if we are adding a new sambaAccount, make sure that we add a
[Samba.git] / source / lib / signal.c
blob9c78fad8862e49ea59925b07f8ebcc0559203a85
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"
25 /****************************************************************************
26 Catch child exits and reap the child zombie status.
27 ****************************************************************************/
29 static void sig_cld(int signum)
31 while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)
35 * Turns out it's *really* important not to
36 * restore the signal handler here if we have real POSIX
37 * signal handling. If we do, then we get the signal re-delivered
38 * immediately - hey presto - instant loop ! JRA.
41 #if !defined(HAVE_SIGACTION)
42 CatchSignal(SIGCLD, sig_cld);
43 #endif
46 /****************************************************************************
47 catch child exits - leave status;
48 ****************************************************************************/
50 static void sig_cld_leave_status(int signum)
53 * Turns out it's *really* important not to
54 * restore the signal handler here if we have real POSIX
55 * signal handling. If we do, then we get the signal re-delivered
56 * immediately - hey presto - instant loop ! JRA.
59 #if !defined(HAVE_SIGACTION)
60 CatchSignal(SIGCLD, sig_cld_leave_status);
61 #else
63 #endif
66 /*******************************************************************
67 Block sigs.
68 ********************************************************************/
70 void BlockSignals(BOOL block,int signum)
72 #ifdef HAVE_SIGPROCMASK
73 sigset_t set;
74 sigemptyset(&set);
75 sigaddset(&set,signum);
76 sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
77 #elif defined(HAVE_SIGBLOCK)
78 if (block) {
79 sigblock(sigmask(signum));
80 } else {
81 sigsetmask(siggetmask() & ~sigmask(signum));
83 #else
84 /* yikes! This platform can't block signals? */
85 static int done;
86 if (!done) {
87 DEBUG(0,("WARNING: No signal blocking available\n"));
88 done=1;
90 #endif
93 /*******************************************************************
94 Catch a signal. This should implement the following semantics:
96 1) The handler remains installed after being called.
97 2) The signal should be blocked during handler execution.
98 ********************************************************************/
100 void CatchSignal(int signum,void (*handler)(int ))
102 #ifdef HAVE_SIGACTION
103 struct sigaction act;
105 ZERO_STRUCT(act);
107 act.sa_handler = handler;
108 #ifdef SA_RESTART
110 * We *want* SIGALRM to interrupt a system call.
112 if(signum != SIGALRM)
113 act.sa_flags = SA_RESTART;
114 #endif
115 sigemptyset(&act.sa_mask);
116 sigaddset(&act.sa_mask,signum);
117 sigaction(signum,&act,NULL);
118 #else /* !HAVE_SIGACTION */
119 /* FIXME: need to handle sigvec and systems with broken signal() */
120 signal(signum, handler);
121 #endif
124 /*******************************************************************
125 Ignore SIGCLD via whatever means is necessary for this OS.
126 ********************************************************************/
128 void CatchChild(void)
130 CatchSignal(SIGCLD, sig_cld);
133 /*******************************************************************
134 Catch SIGCLD but leave the child around so it's status can be reaped.
135 ********************************************************************/
137 void CatchChildLeaveStatus(void)
139 CatchSignal(SIGCLD, sig_cld_leave_status);