Messages in this thread | | | Date | Tue, 15 Feb 2005 13:58:28 +0100 | From | Yves Crespin <> | Subject | sigwait() and 2.6 |
| |
Hi,
Going on a 2.6 kernel, I have a trouble with sigwait()
When I send a kill to this program, the exit code is 143 (signal 15 and core)!
Is there a workaround ?
Thanks,
Yves
gcc -g -Wall -D_REENTRANT=1 -D_THREAD_SAFE=1 s.c -lpthread -o s
/===== début du code =====/
#include <unistd.h> #include <stdio.h> #include <signal.h> #include <pthread.h>
typedef void Sigfunc(int);
#define ThreadBlockSignal() ThreadSignalAction(SIG_BLOCK) #define ThreadUnblockSignal() ThreadSignalAction(SIG_UNBLOCK)
/*----------STATIC------------------*/ extern void ThreadSignalAction(const int how) { sigset_t newmask;
if (sigemptyset(&newmask)<0){ printf("sigemptyset failed"); return; } if (sigaddset(&newmask,SIGTERM)<0){ printf("sigaddset failed"); return; } if (pthread_sigmask(how,&newmask,NULL)){ printf("pthread_sigmask SIG_BLOCK failed"); return; } }
extern Sigfunc * signal_intr(int signo,Sigfunc *func) { struct sigaction act, oact;
act.sa_handler = func; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (signo == SIGALRM){ #ifdef SA_INTERRUPT act.sa_flags |= SA_INTERRUPT; /* Interrupt mode */ #endif /* SA_INTERRUPT */ }else{ #ifdef SA_RESTART /* * automatic restart of interrupted system calls except * if they are operating on a slow device. * For select(): * Under BSD, even if SA_RESTART is specified, select() was * never restarted. * Under SVR4, if SA_RESTART is specified, even select() and * pool() are automatically restarted. */ act.sa_flags |= SA_RESTART; #endif /* SA_RESTART */ if (signo == SIGCHLD){ act.sa_flags |= SA_NOCLDSTOP; /* Don't send SIGCHLD when children stop*/ } }
#ifdef SA_RESETHAND act.sa_flags &= ~SA_RESETHAND; /* signal handle remains installed */ #endif /* SA_RESETHAND */ if (sigaction(signo, &act, &oact) < 0){ return(SIG_ERR); } return(oact.sa_handler); }
extern int WaitSignal(void) { sigset_t newmask; int ret; int sig;
if (sigemptyset(&newmask)<0){ printf("sigemptyset failed"); return -1; } if (sigaddset(&newmask,SIGTERM)<0){ printf("sigaddset failed"); return -1; } printf("Waiting signal ..."); fflush(stdout); ret = sigwait(&newmask,&sig); if (ret!=0){ printf("WaitSignal: sigwait failed %d",ret); }else{ printf("WaitSignal: sigwait sig %d",sig); } return sig; }
int main(int argc,char * const argv[]) { if (signal_intr(SIGTERM,SIG_DFL) == SIG_ERR){ printf("signal %d (set handle) failed",SIGTERM); }
/* -- Main loop */ printf("%lu ready ...",(unsigned long)getpid()); fflush(stdout); int signo;
ThreadUnblockSignal(); signo = WaitSignal(); ThreadBlockSignal(); if (signo==SIGTERM){ printf("\nSIGTERM in main\n"); fflush(stdout); }else{ printf("\n%d in main\n",signo); fflush(stdout); } return 0; }
/===== fin du code =====/
begin:vcard fn:Yves Crespin n:Crespin;Yves org:Quartz adr:Hameau du Pra - CIDEX 322;;39, rue Victor Hugo;CROLLES;;38920;France email;internet:Crespin.Quartz@Wanadoo.fr tel;work:04.76.92.21.91 tel;cell:06.86.42.86.81 x-mozilla-html:FALSE url:http://crespin.quartz.free.fr/ version:2.1 end:vcard
| |