Merge branch 'vendor/OPENSSL'
[dragonfly.git] / contrib / cvs-1.12 / src / exithandle.c
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
11 #include "cvs.h"
12
13 /*
14  * Register a handler for all signals.
15  */
16 void
17 signals_register (RETSIGTYPE (*handler)(int))
18 {
19 #ifndef DONT_USE_SIGNALS
20 #ifdef SIGABRT
21         (void) SIG_register (SIGABRT, handler);
22 #endif
23 #ifdef SIGHUP
24         (void) SIG_register (SIGHUP, handler);
25 #endif
26 #ifdef SIGINT
27         (void) SIG_register (SIGINT, handler);
28 #endif
29 #ifdef SIGQUIT
30         (void) SIG_register (SIGQUIT, handler);
31 #endif
32 #ifdef SIGPIPE
33         (void) SIG_register (SIGPIPE, handler);
34 #endif
35 #ifdef SIGTERM
36         (void) SIG_register (SIGTERM, handler);
37 #endif
38 #endif /* !DONT_USE_SIGNALS */
39 }
40
41
42
43 /*
44  * Register a handler for all signals and exit.
45  */
46 void
47 cleanup_register (void (*handler) (void))
48 {
49     atexit (handler);
50
51     /* Always calling this function before any other exit handlers guarantees
52      * that signals will be blocked by the time the other exit handlers are
53      * called.
54      *
55      * SIG_beginCrSect will be called once for each handler registered via
56      * cleanup_register, but there is no unregister routine for atexit() and
57      * this seems like minimal overhead.
58      *
59      * There is no reason to unblock signals again when the exit handlers are
60      * done since the program will be exiting anyhow.
61      */
62     atexit (SIG_beginCrSect);
63 }