I have a problem with my code C Unix. I'll copy crucial parts: So after the first sigprocmask I send a signal, after the SIG_UNBLOCK, doesn't work the previous handle(gestisciSignalDopoReg) instead the standard handle manage my signal, so it simply terminate the process... What's wrong? Thanks
struct sigaction gestoreSegnale;
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask,SIGTERM);
sigaddset(&mask,SIGINT);
sigaddset(&mask,SIGALRM);
sigaddset(&mask,SIGQUIT);
sigaddset(&mask,SIGHUP);
sigaddset(&mask,SIGSEGV);
sigaddset(&mask,SIGILL);
sigaddset(&mask,SIGPIPE);
void setSegnali(int segn,__sighandler_t handler){
gestoreSegnale.sa_handler=handler;
gestoreSegnale.sa_mask=mask;
sigaction(segn, &gestoreSegnale, NULL);
}
void eseguiSetSegnali(__sighandler_t handler){
setSegnali(SIGQUIT, handler);
setSegnali(SIGSEGV, handler);
setSegnali(SIGILL, handler);
setSegnali(SIGHUP, handler);
setSegnali(SIGTERM, handler);
setSegnali(SIGINT, handler);
}
void main(){
eseguiSetSegnali(gestisciSIGNALDopoReg);
sigprocmask(SIG_BLOCK,&mask,NULL);
.........other part of code.........
sigprocmask(SIG_UNBLOCK,&mask,NULL);
}
please! I need help!
You do not initialize the
sa_flagsfield of yourstruct sigaction, so it may contain garbage values. It is possible that theSA_RESETHANDbit is set, which according to the man page will give you this behavior:If your signal handler has run once, that would cause it to be cleared and return to the default, so you may just need to zero out the flags like:
At any rate, the following little example works:
If run, you see the desired result: