Newlib bug report

This forum is for general developer support questions.

Newlib bug report

Postby rwo » Sun Sep 09, 2018 2:02 am

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 );
}
User avatar
rwo
 
Posts: 15
Joined: Thu Mar 10, 2011 12:03 pm
Location: Denmark

Re: Newlib bug report

Postby xenic » Wed Sep 12, 2018 5:26 pm

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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
 
Posts: 1148
Joined: Sun Jun 19, 2011 1:06 am

Re: Newlib bug report

Postby salass00 » Wed Sep 12, 2018 6:48 pm

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 */
}
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 506
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland

Re: Newlib bug report

Postby chris » Mon Nov 12, 2018 12:27 am

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.
chris
 
Posts: 552
Joined: Sat Jun 18, 2011 12:05 pm


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 10 guests