1 /*****************************************************************************
3 * File SigHand.c: define a set of functions for signal manipulation
5 * Author: S. Piccardi Dec. 2002
7 * $Id: SigHand.c,v 1.1 2002/12/03 11:06:05 piccardi Exp $
9 *****************************************************************************/
10 #include <errno.h> /* error simbol definitions */
11 #include <stdio.h> /* standard I/O functions */
12 #include <signal.h> /* signal handling declarations */
13 #include <sys/types.h>
21 * Initialize a signal handler.
22 * To enable the signal handling a process we need to tell it to
23 * kernel; this is done writing all needed info to a sigaction structure
24 * named sigact, and then callind sigaction() system call passing the
25 * information stored in the sigact structure variable.
27 * Input: the signal to handle
28 * the signal handler function
29 * Return: the previous sigaction structure
31 inline SigFunc * Signal(int signo, SigFunc *func)
33 struct sigaction new_handl, old_handl;
34 new_handl.sa_handler=func;
35 /* clear signal mask: no signal blocked during execution of func */
36 if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
37 perror("cannot initializes the signal set to empty"); /* see mess. */
40 new_handl.sa_flags=0; /* init to 0 all flags */
41 /* change action for signo signal */
42 if (sigaction(signo,&new_handl,&old_handl)){
43 perror("sigaction failed on signal action setting");
46 return (old_handl.sa_handler);
49 * Functions: HandSigCHLD
50 * Generic handler for SIGCHLD signal
52 * Simone Piccardi Dec. 2002
53 * $Id: SigHand.c,v 1.1 2002/12/03 11:06:05 piccardi Exp $
55 void HandSigCHLD(int sig)
60 /* save errno current value */
65 pid = waitpid(WAIT_ANY, &status, WNOHANG);
67 debug("child %d terminated with status %x\n", pid, status);
69 } while ((pid > 0) && (errno == EINTR));
70 /* restore errno value*/