Page 1 of 1

Newlib bug report

PostPosted: Sun Sep 09, 2018 2:02 am
by rwo
Okay .. I found the energy to code. and it revealed a buggie in Newlib's waitselect()

Basicly if I set some Amiga Signaled to break on like CTRL+C.. I want the break bits in Mask.. but its simple returning Zero

newlib.library 53.36 (17/09-2016) (A1222 version)

Code: Select all

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/socket.h>

#include <stdio.h>
#include <string.h>

int main( int argc UNUSED, char **argv UNUSED )
{
unsigned int mask;
fd_set read;
int s;

   signal( SIGINT, SIG_IGN );

   s = socket( AF_INET, SOCK_STREAM, 0 );

   FD_ZERO( &read );
   FD_SET( s, &read );

   mask = SIGBREAKF_CTRL_C;

   int32 val = waitselect( s + 1, & read, NULL, NULL, NULL, & mask );

   printf( "Mask : %08lx, Val : %ld\n", mask, val );

   return( 0 );
}

Re: Newlib bug report

PostPosted: Wed Sep 12, 2018 5:26 pm
by xenic
rwo wrote:Okay .. I found the energy to code. and it revealed a buggie in Newlib's waitselect()

Basicly if I set some Amiga Signaled to break on like CTRL+C.. I want the break bits in Mask.. but its simple returning Zero

I could be wrong, but I suspect that Newlib's waitselect() is just a stub for the bsdsocket.library WaitSelect() function. If that's the case then this quote from the bsdsocket autodoc might explain your problem:
    Reception of the standard break signal (e.g. via Ctrl+C) will cause
    WaitSelect() to return -1 and set the error code to EINTR.
    Additionally, the standard break signal will be posted. This means
    that the signal will still be set when WaitSelect() returns, and
    can be tested. If -1 is returned, the contents of the user signal
    mask pointed to by the 'signals' parameter will be undefined.
You could test for Ctrl+C with SetSignal() and possibly clear it if set.

Re: Newlib bug report

PostPosted: Wed Sep 12, 2018 6:48 pm
by salass00
xenic wrote:You could test for Ctrl+C with SetSignal() and possibly clear it if set.


For common use cases like the above CheckSignal() is much simpler to use.

The following code checks for set CTRL-C signal and clears it:
Code: Select all
if (IDOS->CheckSignal(SIGBREAKF_CTRL_C)) {
    /* CTRL-C signal received */
}


and is equivalent to the following using IExec->SetSignal():
Code: Select all
if (IExec->SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
    /* CTRL-C signal received */
}

Re: Newlib bug report

PostPosted: Mon Nov 12, 2018 12:27 am
by chris
I've seen a problem with this myself. My notes say (and this is all the information I have):
Code: Select all
WaitSelect() from bsdsocket.library returns -1 if the task was
          * signalled with a Ctrl-C.  waitselect() from newlib.library does not.
          * Adding the Ctrl-C signal to our user signal mask causes a Ctrl-C to
          * occur sporadically.  Otherwise we never get a -1 except on error.