2 Unix SMB/CIFS implementation.
3 signal handling functions
5 Copyright (C) Andrew Tridgell 1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/wait.h"
26 * @brief Signal handling
29 /****************************************************************************
30 Catch child exits and reap the child zombie status.
31 ****************************************************************************/
33 static void sig_cld(int signum
)
35 while (waitpid((pid_t
)-1,(int *)NULL
, WNOHANG
) > 0)
39 * Turns out it's *really* important not to
40 * restore the signal handler here if we have real POSIX
41 * signal handling. If we do, then we get the signal re-delivered
42 * immediately - hey presto - instant loop ! JRA.
45 #if !defined(HAVE_SIGACTION)
46 CatchSignal(SIGCLD
, sig_cld
);
50 /****************************************************************************
51 catch child exits - leave status;
52 ****************************************************************************/
54 static void sig_cld_leave_status(int signum
)
57 * Turns out it's *really* important not to
58 * restore the signal handler here if we have real POSIX
59 * signal handling. If we do, then we get the signal re-delivered
60 * immediately - hey presto - instant loop ! JRA.
63 #if !defined(HAVE_SIGACTION)
64 CatchSignal(SIGCLD
, sig_cld_leave_status
);
72 void BlockSignals(bool block
, int signum
)
74 #ifdef HAVE_SIGPROCMASK
77 sigaddset(&set
,signum
);
78 sigprocmask(block
?SIG_BLOCK
:SIG_UNBLOCK
,&set
,NULL
);
79 #elif defined(HAVE_SIGBLOCK)
81 sigblock(sigmask(signum
));
83 sigsetmask(siggetmask() & ~sigmask(signum
));
86 /* yikes! This platform can't block signals? */
89 DEBUG(0,("WARNING: No signal blocking available\n"));
96 Catch a signal. This should implement the following semantics:
98 1) The handler remains installed after being called.
99 2) The signal should be blocked during handler execution.
102 void (*CatchSignal(int signum
,void (*handler
)(int )))(int)
104 #ifdef HAVE_SIGACTION
105 struct sigaction act
;
106 struct sigaction oldact
;
110 act
.sa_handler
= handler
;
113 * We *want* SIGALRM to interrupt a system call.
115 if(signum
!= SIGALRM
)
116 act
.sa_flags
= SA_RESTART
;
118 sigemptyset(&act
.sa_mask
);
119 sigaddset(&act
.sa_mask
,signum
);
120 sigaction(signum
,&act
,&oldact
);
121 return oldact
.sa_handler
;
122 #else /* !HAVE_SIGACTION */
123 /* FIXME: need to handle sigvec and systems with broken signal() */
124 return signal(signum
, handler
);
129 Ignore SIGCLD via whatever means is necessary for this OS.
132 void CatchChild(void)
134 CatchSignal(SIGCLD
, sig_cld
);
138 Catch SIGCLD but leave the child around so it's status can be reaped.
141 void CatchChildLeaveStatus(void)
143 CatchSignal(SIGCLD
, sig_cld_leave_status
);