Newlib bug report

This forum is for general developer support questions.
Post Reply
User avatar
rwo
Posts: 15
Joined: Thu Mar 10, 2011 11:03 am
Location: Denmark

Newlib bug report

Post 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 );
}
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Newlib bug report

Post 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.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

Re: Newlib bug report

Post 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 */
}
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

Re: Newlib bug report

Post 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.
Post Reply