1 /* 2 * Copyright (c) 2003, Derek Price and Ximbiot <http://ximbiot.com> 3 * 4 * You may distribute under the terms of the GNU General Public License 5 * as specified in the README file that comes with the CVS source 6 * distribution. 7 * 8 * This is a convenience wrapper for some of the functions in lib/sighandle.c. 9 */ 10 #include <sys/cdefs.h> 11 __RCSID("$NetBSD: exithandle.c,v 1.4 2016/05/17 14:00:09 christos Exp $"); 12 13 #include "cvs.h" 14 15 /* 16 * Register a handler for all signals. 17 */ 18 void signals_register(RETSIGTYPE (* handler)(int))19signals_register (RETSIGTYPE (*handler)(int)) 20 { 21 #ifndef DONT_USE_SIGNALS 22 #ifdef SIGABRT 23 (void) SIG_register (SIGABRT, handler); 24 #endif 25 #ifdef SIGHUP 26 (void) SIG_register (SIGHUP, handler); 27 #endif 28 #ifdef SIGINT 29 (void) SIG_register (SIGINT, handler); 30 #endif 31 #ifdef SIGQUIT 32 (void) SIG_register (SIGQUIT, handler); 33 #endif 34 #ifdef SIGPIPE 35 (void) signal (SIGPIPE, SIG_IGN); 36 #endif 37 #ifdef SIGTERM 38 (void) SIG_register (SIGTERM, handler); 39 #endif 40 #endif /* !DONT_USE_SIGNALS */ 41 } 42 43 44 45 /* 46 * Register a handler for all signals and exit. 47 */ 48 void cleanup_register(void (* handler)(void))49cleanup_register (void (*handler) (void)) 50 { 51 atexit (handler); 52 53 /* Always calling this function before any other exit handlers guarantees 54 * that signals will be blocked by the time the other exit handlers are 55 * called. 56 * 57 * SIG_beginCrSect will be called once for each handler registered via 58 * cleanup_register, but there is no unregister routine for atexit() and 59 * this seems like minimal overhead. 60 * 61 * There is no reason to unblock signals again when the exit handlers are 62 * done since the program will be exiting anyhow. 63 */ 64 atexit (SIG_beginCrSect); 65 } 66