X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FSigHand.c;h=a37fac5ab28daa68412e392ce4e07f431a5b7fcf;hp=89585e3cc63c3f3e485aca5a4017fae8288414f3;hb=fa15a3f1ecd64efd8440e46d398fd9976abc3d25;hpb=b1ead1b930038e4f7cd6ee7f737d7ee4699a068c diff --git a/sources/SigHand.c b/sources/SigHand.c index 89585e3..a37fac5 100644 --- a/sources/SigHand.c +++ b/sources/SigHand.c @@ -22,14 +22,12 @@ * * Author: S. Piccardi Dec. 2002 * - * $Id: SigHand.c,v 1.5 2003/05/02 09:55:14 piccardi Exp $ - * *****************************************************************************/ -#include /* error simbol definitions */ -#include /* standard I/O functions */ -#include /* signal handling declarations */ -#include -#include +#include /* error definitions and routines */ +#include /* standard I/O library */ +#include /* signal constants, types and functions */ +#include /* primitive system data types */ +#include /* process termination constants and functions */ #include "Gapil.h" #include "macros.h" @@ -49,24 +47,54 @@ inline SigFunc * Signal(int signo, SigFunc *func) { struct sigaction new_handl, old_handl; - new_handl.sa_handler = func; /* set signal handler */ + 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 */ + 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)){ + 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.5 2003/05/02 09:55:14 piccardi Exp $ */ void HandSigCHLD(int sig) { @@ -79,10 +107,10 @@ 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); - } - } while ((pid > 0) && (errno == EINTR)); +// if (pid > 0) { +// debug("child %d terminated with status %x\n", pid, status); +// } + } while (pid > 0); /* restore errno value*/ errno = errno_save; /* return */