3 * Copyright (C) 2002 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /*****************************************************************************
21 * File SigHand.c: define a set of functions for signal manipulation
23 * Author: S. Piccardi Dec. 2002
25 * $Id: SigHand.c,v 1.3 2002/12/11 00:51:38 piccardi Exp $
27 *****************************************************************************/
28 #include <errno.h> /* error simbol definitions */
29 #include <stdio.h> /* standard I/O functions */
30 #include <signal.h> /* signal handling declarations */
31 #include <sys/types.h>
39 * Initialize a signal handler.
40 * To enable the signal handling a process we need to tell it to
41 * kernel; this is done writing all needed info to a sigaction structure
42 * named sigact, and then callind sigaction() system call passing the
43 * information stored in the sigact structure variable.
45 * Input: the signal to handle
46 * the signal handler function
47 * Return: the previous sigaction structure
49 inline SigFunc * Signal(int signo, SigFunc *func)
51 struct sigaction new_handl, old_handl;
52 new_handl.sa_handler = func; /* set signal handler */
53 /* clear signal mask: no signal blocked during execution of func */
54 if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
57 new_handl.sa_flags=0; /* init to 0 all flags */
58 /* change action for signo signal */
59 if (sigaction(signo,&new_handl,&old_handl)){
62 return (old_handl.sa_handler);
65 * Functions: HandSigCHLD
66 * Generic handler for SIGCHLD signal
68 * Simone Piccardi Dec. 2002
69 * $Id: SigHand.c,v 1.3 2002/12/11 00:51:38 piccardi Exp $
71 void HandSigCHLD(int sig)
76 /* save errno current value */
81 pid = waitpid(WAIT_ANY, &status, WNOHANG);
83 debug("child %d terminated with status %x\n", pid, status);
85 } while ((pid > 0) && (errno == EINTR));
86 /* restore errno value*/