2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/types.h>
36 static int caused[NSIG]; /* An array of pending signals */
37 static int necessary; /* Anything set ? */
38 static sig_type handler[NSIG]; /* all start at SIG_DFL */
41 /* Record a signal in the "caused" array */
44 signal_recorder(int sig)
52 * Set up signal_recorder, and record handler as the function to ultimately
53 * call in handle_signal()
57 sig_signal(int sig, sig_type fn)
61 if (sig <= 0 || sig > NSIG) {
62 /* Oops - we must be a bit out of date (too many sigs ?) */
63 log_Printf(LogALERT, "Eeek! %s:%d: I must be out of date!\n",
65 return signal(sig, fn);
67 Result = handler[sig - 1];
68 if (fn == SIG_DFL || fn == SIG_IGN) {
70 handler[sig - 1] = (sig_type) 0;
72 handler[sig - 1] = fn;
73 signal(sig, signal_recorder);
80 /* Call the handlers for any pending signals */
91 /* We've *probably* got something in `caused' set */
93 /* `necessary' might go back to 1 while we're in here.... */
96 for (sig = 0; sig < NSIG; sig++)
101 (*handler[sig])(sig + 1);