In my program,sigaddset()
is failing with error:
sigaddset: Invalid Seek
which corresponds to ESPIPE
in errno.h
but this error is not mentioned in the standard definition of sigaddset()
.
The complete code is too long, I am posting the required parts:
The signal handling routine:
void* Ctrl_C_handler(void *arg)
{
int *sock_fd_ptr = (int*)arg;
sigset_t set;
int err;
err = sigemptyset(&set); // Clear the signals holder set
if(!err) perror("sigemptyset(&set)");
err = sigaddset(&set, SIGINT); // Add the SIGINT: Ctrl+C
if(!err) perror("siaddset(&set, SIGINT)");
err = sigthreadmask(SIG_UNBLOCK, &set, NULL); // Set mask as to unblock SIGINT
if(!err) perror("sigthreadmask(SIG_SETMASK, &set, NULL)");
while(1) // Ctrl+C
{
sig = sigwait(&set); // Wait for signal to occur
if(sig == SIGINT)
{
printf("Ctrl+C detected by server !!\n");
printf("No more connections will be accepted!!");
if(*sock_fd_ptr > 0)
{
close(server_sock_fd);
*sock_fd_ptr = -1;
break;
}
}
else
{
printf("Error handling the signal, SigHandlerThread exiting..\n")
perror("sigwait(&set)");
break;
}
}
return NULL;
}
Inside main():
/*********** Signal Handling *************/
sigset_t set; // declare a set to hold the signals
err = sigfillset(&set); // Fill the set with all the signals
if(!err) perror("sigfillset(&set)");
err = sigthreadmask(SIG_BLOCK, set, NULL); // Block/Mask the signals in the set
if(!err) perror("sigthreadmask(SIG_BLOCK, &set, NULL)");
err = pthread_create(&sig_handler_tid, NULL, Ctrl_C_handler, (void *)&sock_fd);
// Create a thread for handling signals
if(!err) perror("pthread_create");
What am I missing or doing wrong or understanding wrong?
P.S.: I have recently started programming using signals.
Operating Sys: SLES 10 SP3 x86-64