X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FSigHand.c;h=6112700af7a7525eba3c574aecd01d95dc7373ca;hp=53d185a08f50be41176c66ac1683fa2c2e840b0e;hb=eefeeaee57a56cfe1ff8c02a26c44d6f87f1368c;hpb=9c3be0a6a901fad667ba1abcd8b46c712020cf26 diff --git a/sources/SigHand.c b/sources/SigHand.c index 53d185a..6112700 100644 --- a/sources/SigHand.c +++ b/sources/SigHand.c @@ -22,7 +22,7 @@ * * Author: S. Piccardi Dec. 2002 * - * $Id: SigHand.c,v 1.2 2002/12/03 22:30:11 piccardi Exp $ + * $Id: SigHand.c,v 1.7 2003/05/06 14:05:12 piccardi Exp $ * *****************************************************************************/ #include /* error simbol definitions */ @@ -49,26 +49,55 @@ inline SigFunc * Signal(int signo, SigFunc *func) { struct sigaction new_handl, old_handl; - new_handl.sa_handler=func; + new_handl.sa_handler = func; /* set signal handler */ /* clear signal mask: no signal blocked during execution of func */ - if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */ - perror("cannot initializes the signal set to empty"); /* see mess. */ - exit(1); + if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */ + return SIG_ERR; } - new_handl.sa_flags=0; /* init to 0 all flags */ + new_handl.sa_flags=0; /* init to 0 all flags */ /* change action for signo signal */ - if (sigaction(signo,&new_handl,&old_handl)){ - perror("sigaction failed on signal action setting"); - exit(1); + if (sigaction(signo, &new_handl, &old_handl)){ + return SIG_ERR; } return (old_handl.sa_handler); } + +/* + * Function SignalRestart + * Initialize a signal handler. + * To enable the signal handling a process we need to tell it to + * kernel; this is done writing all needed info to a sigaction structure + * named sigact, and then callind sigaction() system call passing the + * information stored in the sigact structure variable. + * This version enable BSD semantics with SA_RESTART + * + * Input: the signal to handle + * the signal handler function + * Return: the previous sigaction structure + */ +inline SigFunc * SignalRestart(int signo, SigFunc *func) +{ + struct sigaction new_handl, old_handl; + new_handl.sa_handler = func; /* set signal handler */ + new_handl.sa_flags = SA_RESTART; /* restart system call */ + /* clear signal mask: no signal blocked during execution of func */ + if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */ + return SIG_ERR; + } + /* change action for signo signal */ + if (sigaction(signo, &new_handl, &old_handl)){ + return SIG_ERR; + } + return (old_handl.sa_handler); +} + + /* * Functions: HandSigCHLD * Generic handler for SIGCHLD signal * * Simone Piccardi Dec. 2002 - * $Id: SigHand.c,v 1.2 2002/12/03 22:30:11 piccardi Exp $ + * $Id: SigHand.c,v 1.7 2003/05/06 14:05:12 piccardi Exp $ */ void HandSigCHLD(int sig) { @@ -81,9 +110,9 @@ void HandSigCHLD(int sig) do { errno = 0; pid = waitpid(WAIT_ANY, &status, WNOHANG); - if (pid > 0) { - debug("child %d terminated with status %x\n", pid, status); - } +// if (pid > 0) { +// debug("child %d terminated with status %x\n", pid, status); +// } } while ((pid > 0) && (errno == EINTR)); /* restore errno value*/ errno = errno_save;