sig.c (34331) | sig.c (36285) |
---|---|
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 * | 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.11 1997/12/21 12:11:08 brian Exp $ | 26 * $Id: sig.c,v 1.11.2.5 1998/05/01 19:25:56 brian Exp $ |
27 */ 28 29#include <sys/types.h> 30 31#include <signal.h> 32 | 27 */ 28 29#include <sys/types.h> 30 31#include <signal.h> 32 |
33#include "command.h" 34#include "mbuf.h" | |
35#include "log.h" 36#include "sig.h" 37 38static int caused[NSIG]; /* An array of pending signals */ 39static sig_type handler[NSIG]; /* all start at SIG_DFL */ 40 41 42/* Record a signal in the "caused" array */ --- 6 unchanged lines hidden (view full) --- 49 50 51/* 52 * Set up signal_recorder, and record handler as the function to ultimately 53 * call in handle_signal() 54*/ 55 56sig_type | 33#include "log.h" 34#include "sig.h" 35 36static int caused[NSIG]; /* An array of pending signals */ 37static sig_type handler[NSIG]; /* all start at SIG_DFL */ 38 39 40/* Record a signal in the "caused" array */ --- 6 unchanged lines hidden (view full) --- 47 48 49/* 50 * Set up signal_recorder, and record handler as the function to ultimately 51 * call in handle_signal() 52*/ 53 54sig_type |
57pending_signal(int sig, sig_type fn) | 55sig_signal(int sig, sig_type fn) |
58{ 59 sig_type Result; 60 61 if (sig <= 0 || sig > NSIG) { 62 /* Oops - we must be a bit out of date (too many sigs ?) */ | 56{ 57 sig_type Result; 58 59 if (sig <= 0 || sig > NSIG) { 60 /* Oops - we must be a bit out of date (too many sigs ?) */ |
63 LogPrintf(LogALERT, "Eeek! %s:%s: I must be out of date!\n", | 61 log_Printf(LogALERT, "Eeek! %s:%d: I must be out of date!\n", |
64 __FILE__, __LINE__); 65 return signal(sig, fn); 66 } 67 Result = handler[sig - 1]; 68 if (fn == SIG_DFL || fn == SIG_IGN) { 69 signal(sig, fn); 70 handler[sig - 1] = (sig_type) 0; 71 } else { 72 handler[sig - 1] = fn; 73 signal(sig, signal_recorder); 74 } 75 caused[sig - 1] = 0; 76 return Result; 77} 78 79 80/* Call the handlers for any pending signals */ 81 82void | 62 __FILE__, __LINE__); 63 return signal(sig, fn); 64 } 65 Result = handler[sig - 1]; 66 if (fn == SIG_DFL || fn == SIG_IGN) { 67 signal(sig, fn); 68 handler[sig - 1] = (sig_type) 0; 69 } else { 70 handler[sig - 1] = fn; 71 signal(sig, signal_recorder); 72 } 73 caused[sig - 1] = 0; 74 return Result; 75} 76 77 78/* Call the handlers for any pending signals */ 79 80void |
83handle_signals() | 81sig_Handle() |
84{ 85 int sig; 86 int got; 87 88 do { 89 got = 0; 90 for (sig = 0; sig < NSIG; sig++) 91 if (caused[sig]) { 92 caused[sig]--; 93 got++; 94 (*handler[sig]) (sig + 1); 95 } 96 } while (got); 97} | 82{ 83 int sig; 84 int got; 85 86 do { 87 got = 0; 88 for (sig = 0; sig < NSIG; sig++) 89 if (caused[sig]) { 90 caused[sig]--; 91 got++; 92 (*handler[sig]) (sig + 1); 93 } 94 } while (got); 95} |