I try yo use sigtimedwait according to the code below, I got this message “Caught unexpected signal 4714397, error 0, code 370078816”. Does anyone know where I can the corresponding map of those number?
sigset_t oMask;
siginfo_t oInfo;
struct timespec oTimeout;
/* Create a mask holding */
sigemptyset(&oMask);
sigaddset(&oMask, SIGINT );
sigaddset(&oMask, SIGTERM );
/* Set the mask for our main thread to include SIGINT */
pthread_sigmask( SIG_BLOCK, &oMask, NULL );
/* Max wait for ^C set to 5 seconds */
oTimeout.tv_sec = 5;
oTimeout.tv_nsec = 0;
int iRet = -1;
bool bStop = false;
while (!bStop)
{
iRet = sigtimedwait(&oMask, &oInfo, &oTimeout);
if ( -1 == iRet && EAGAIN == errno)
{
}
else
{
switch (oInfo.si_signo)
{
case SIGINT:
printf( "Caught SIGINT in sigtimedwait( )\n" );
bStop = true;
break;
case SIGTERM:
printf( "Caught SIGTERM in sigtimedwait( )\n" );
bStop = true;
break;
/* Should never really get to default */
default:
printf( "Caught unexpected signal %d, error %d, code %d\n", oInfo.si_signo, oInfo.si_errno,oInfo.si_code),oInfo.si_code) ;
break;
}
}
}
I think you may be missing some logic there. If you get an error return of -1 but
errnois notEAGAIN, you seem to assume it worked and theoInfovariable contains valid data.This may cause a problem if your process is interrupted during the wait, since one of the valid return codes is
EINTR.In that case,
oInfois going to contain whatever rubbish was on the stack when you entered that function, something borne out by the fact that I’m pretty certain signals don’t go up to 4714397 🙂Simple way to find out: print out
iRetanderrnoin your default case.There’s also something hideously wrong with your line:
but I’m going to assume that’s just a typo on your part and it’s really something like:
The change I would make to it would be: