]>
diplodocus.org Git - nmh/blob - sbr/signals.c
1 /* signals.c -- general signals interface for nmh
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
14 * A version of the function `signal' that uses reliable
15 * signals, if the machine supports them. Also, (assuming
16 * OS support), it restarts interrupted system calls for all
17 * signals except SIGALRM.
19 * Since we are now assuming POSIX signal support everywhere, we always
20 * use reliable signals.
24 SIGNAL (int sig
, SIGNAL_HANDLER func
)
26 struct sigaction act
, oact
;
28 act
.sa_handler
= func
;
29 sigemptyset(&act
.sa_mask
);
34 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
38 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
41 if (sigaction(sig
, &act
, &oact
) < 0)
43 return oact
.sa_handler
;
48 * A version of the function `signal' that will set
49 * the handler of `sig' to `func' if the signal is
50 * not currently set to SIG_IGN. Also uses reliable
51 * signals if available.
54 SIGNAL2 (int sig
, SIGNAL_HANDLER func
)
56 struct sigaction act
, oact
;
58 if (sigaction(sig
, NULL
, &oact
) < 0)
60 if (oact
.sa_handler
!= SIG_IGN
) {
61 act
.sa_handler
= func
;
62 sigemptyset(&act
.sa_mask
);
67 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
71 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
74 if (sigaction(sig
, &act
, &oact
) < 0)
77 return oact
.sa_handler
;
82 * For use by nmh_init().
85 setup_signal_handlers(void) {
87 * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
88 * files when the user terminates the process early. And also a
89 * few other common signals that can be thrown due to bugs, stack
93 if (SIGNAL(SIGHUP
, remove_registered_files
) == SIG_ERR
||
94 SIGNAL(SIGINT
, remove_registered_files
) == SIG_ERR
||
95 SIGNAL(SIGQUIT
, remove_registered_files
) == SIG_ERR
||
96 SIGNAL(SIGTERM
, remove_registered_files
) == SIG_ERR
||
97 SIGNAL(SIGILL
, remove_registered_files
) == SIG_ERR
||
99 SIGNAL(SIGBUS
, remove_registered_files
) == SIG_ERR
||
101 SIGNAL(SIGSEGV
, remove_registered_files
) == SIG_ERR
) {