add another registry rpc (opnum 0x14). Have no idea what it's real name
[Samba.git] / source / lib / signal.c
blobdceb3b53bce9eaa3c1f3f002e730d0ba3b7b5875
1 /*
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 /****************************************************************************
25 Catch child exits and reap the child zombie status.
26 ****************************************************************************/
28 static void sig_cld(int signum)
30 while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0)
34 * Turns out it's *really* important not to
35 * restore the signal handler here if we have real POSIX
36 * signal handling. If we do, then we get the signal re-delivered
37 * immediately - hey presto - instant loop ! JRA.
40 #if !defined(HAVE_SIGACTION)
41 CatchSignal(SIGCLD, sig_cld);
42 #endif
45 /****************************************************************************
46 catch child exits - leave status;
47 ****************************************************************************/
49 static void sig_cld_leave_status(int signum)
52 * Turns out it's *really* important not to
53 * restore the signal handler here if we have real POSIX
54 * signal handling. If we do, then we get the signal re-delivered
55 * immediately - hey presto - instant loop ! JRA.
58 #if !defined(HAVE_SIGACTION)
59 CatchSignal(SIGCLD, sig_cld_leave_status);
60 #else
62 #endif
65 /*******************************************************************
66 Block sigs.
67 ********************************************************************/
69 void BlockSignals(BOOL block,int signum)
71 #ifdef HAVE_SIGPROCMASK
72 sigset_t set;
73 sigemptyset(&set);
74 sigaddset(&set,signum);
75 sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
76 #elif defined(HAVE_SIGBLOCK)
77 if (block) {
78 sigblock(sigmask(signum));
79 } else {
80 sigsetmask(siggetmask() & ~sigmask(signum));
82 #else
83 /* yikes! This platform can't block signals? */
84 static int done;
85 if (!done) {
86 DEBUG(0,("WARNING: No signal blocking available\n"));
87 done=1;
89 #endif
92 /*******************************************************************
93 Catch a signal. This should implement the following semantics:
95 1) The handler remains installed after being called.
96 2) The signal should be blocked during handler execution.
97 ********************************************************************/
99 void (*CatchSignal(int signum,void (*handler)(int )))(int)
101 #ifdef HAVE_SIGACTION
102 struct sigaction act;
103 struct sigaction oldact;
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,&oldact);
118 return oldact.sa_handler;
119 #else /* !HAVE_SIGACTION */
120 /* FIXME: need to handle sigvec and systems with broken signal() */
121 return signal(signum, handler);
122 #endif
125 /*******************************************************************
126 Ignore SIGCLD via whatever means is necessary for this OS.
127 ********************************************************************/
129 void CatchChild(void)
131 CatchSignal(SIGCLD, sig_cld);
134 /*******************************************************************
135 Catch SIGCLD but leave the child around so it's status can be reaped.
136 ********************************************************************/
138 void CatchChildLeaveStatus(void)
140 CatchSignal(SIGCLD, sig_cld_leave_status);