This commit was manufactured by cvs2svn to create tag
[Samba/gbeck.git] / source / lib / signal.c
blobbb1c6fe189b5d98ea3d9bb554b16b6370593b494
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 signal handling functions
6 Copyright (C) Andrew Tridgell 1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
26 /****************************************************************************
27 catch child exits
28 ****************************************************************************/
29 static void sig_cld(int signum)
31 while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ;
33 CatchSignal(SIGCLD, sig_cld);
38 /*******************************************************************
39 block sigs
40 ********************************************************************/
41 void BlockSignals(BOOL block,int signum)
43 #ifdef HAVE_SIGPROCMASK
44 sigset_t set;
45 sigemptyset(&set);
46 sigaddset(&set,signum);
47 sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
48 #elif defined(HAVE_SIGBLOCK)
49 int block_mask = sigmask(signum);
50 static int oldmask = 0;
51 if (block) {
52 oldmask = sigblock(block_mask);
53 } else {
54 sigsetmask(oldmask);
56 #else
57 /* yikes! This platform can't block signals? */
58 static int done;
59 if (!done) {
60 DEBUG(0,("WARNING: No signal blocking available\n"));
61 done=1;
63 #endif
68 /*******************************************************************
69 catch a signal. This should implement the following semantics:
71 1) the handler remains installed after being called
72 2) the signal should be blocked during handler execution
73 ********************************************************************/
74 void CatchSignal(int signum,void (*handler)(int ))
76 #ifdef HAVE_SIGACTION
77 struct sigaction act;
79 ZERO_STRUCT(act);
81 act.sa_handler = handler;
82 #ifdef SA_RESTART
83 act.sa_flags = SA_RESTART;
84 #endif
85 sigemptyset(&act.sa_mask);
86 sigaddset(&act.sa_mask,signum);
87 sigaction(signum,&act,NULL);
88 #else
89 /* FIXME: need to handle sigvec and systems with broken signal() */
90 signal(signum, handler);
91 #endif
96 /*******************************************************************
97 ignore SIGCLD via whatever means is necessary for this OS
98 ********************************************************************/
99 void CatchChild(void)
101 CatchSignal(SIGCLD, sig_cld);