1/*- 2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 * |
26 * $Id: sig.c,v 1.13 1998/05/21 21:48:20 brian Exp $ |
27 */ 28 29#include <sys/types.h> 30 31#include <signal.h> 32 33#include "log.h" 34#include "sig.h" 35 36static int caused[NSIG]; /* An array of pending signals */ |
37static int necessary; /* Anything set ? */ |
38static sig_type handler[NSIG]; /* all start at SIG_DFL */ 39 40 41/* Record a signal in the "caused" array */ 42 43static void 44signal_recorder(int sig) 45{ 46 caused[sig - 1]++; |
47 necessary = 1; |
48} 49 50 51/* 52 * Set up signal_recorder, and record handler as the function to ultimately 53 * call in handle_signal() 54*/ 55 --- 18 unchanged lines hidden (view full) --- 74 } 75 caused[sig - 1] = 0; 76 return Result; 77} 78 79 80/* Call the handlers for any pending signals */ 81 |
82int |
83sig_Handle() 84{ 85 int sig; 86 int got; |
87 int result; |
88 |
89 result = 0; 90 if (necessary) { 91 /* We've *probably* got something in `caused' set */ 92 necessary = 0; 93 /* `necessary' might go back to 1 while we're in here.... */ 94 do { 95 got = 0; 96 for (sig = 0; sig < NSIG; sig++) 97 if (caused[sig]) { 98 caused[sig]--; 99 got++; 100 result++; 101 (*handler[sig])(sig + 1); 102 } 103 } while (got); 104 } 105 106 return result; |
107} |