X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FSigHand.c;fp=sources%2FSigHand.c;h=12a7c5b4bf1ab04d73655277cfd0462064ecd9ab;hp=0000000000000000000000000000000000000000;hb=6483a787322c614bc6282a0bf0ee001f1bf54b44;hpb=78a82bdb333ca71e395ba39a5c03745761341150 diff --git a/sources/SigHand.c b/sources/SigHand.c new file mode 100644 index 0000000..12a7c5b --- /dev/null +++ b/sources/SigHand.c @@ -0,0 +1,74 @@ +/***************************************************************************** + * + * File SigHand.c: define a set of functions for signal manipulation + * + * Author: S. Piccardi Dec. 2002 + * + * $Id: SigHand.c,v 1.1 2002/12/03 11:06:05 piccardi Exp $ + * + *****************************************************************************/ +#include /* error simbol definitions */ +#include /* standard I/O functions */ +#include /* signal handling declarations */ +#include +#include + +#include "Gapil.h" +#include "macros.h" + +/* + * Function Signal + * 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. + * + * Input: the signal to handle + * the signal handler function + * Return: the previous sigaction structure + */ +inline SigFunc * Signal(int signo, SigFunc *func) +{ + struct sigaction new_handl, old_handl; + new_handl.sa_handler=func; + /* 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); + } + 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); + } + return (old_handl.sa_handler); +} +/* + * Functions: HandSigCHLD + * Generic handler for SIGCHLD signal + * + * Simone Piccardi Dec. 2002 + * $Id: SigHand.c,v 1.1 2002/12/03 11:06:05 piccardi Exp $ + */ +void HandSigCHLD(int sig) +{ + int errno_save; + int status; + pid_t pid; + /* save errno current value */ + errno_save = errno; + /* loop until no */ + 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)); + /* restore errno value*/ + errno = errno_save; + /* return */ + return; +}