]>
diplodocus.org Git - nmh/blob - sbr/signals.c
3 * signals.c -- general signals interface for nmh
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/signals.h>
14 extern void remove_registered_files(int);
18 * A version of the function `signal' that uses reliable
19 * signals, if the machine supports them. Also, (assuming
20 * OS support), it restarts interrupted system calls for all
21 * signals except SIGALRM.
23 * Since we are now assuming POSIX signal support everywhere, we always
24 * use reliable signals.
28 SIGNAL (int sig
, SIGNAL_HANDLER func
)
30 struct sigaction act
, oact
;
32 act
.sa_handler
= func
;
33 sigemptyset(&act
.sa_mask
);
38 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
42 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
45 if (sigaction(sig
, &act
, &oact
) < 0)
47 return (oact
.sa_handler
);
52 * A version of the function `signal' that will set
53 * the handler of `sig' to `func' if the signal is
54 * not currently set to SIG_IGN. Also uses reliable
55 * signals if available.
58 SIGNAL2 (int sig
, SIGNAL_HANDLER func
)
60 struct sigaction act
, oact
;
62 if (sigaction(sig
, NULL
, &oact
) < 0)
64 if (oact
.sa_handler
!= SIG_IGN
) {
65 act
.sa_handler
= func
;
66 sigemptyset(&act
.sa_mask
);
71 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
75 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
78 if (sigaction(sig
, &act
, &oact
) < 0)
81 return (oact
.sa_handler
);
86 * For use by nmh_init().
89 setup_signal_handlers() {
91 * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
92 * files when the user terminates the process early. And also a
93 * few other common signals that can be thrown due to bugs, stack
97 if (SIGNAL(SIGHUP
, remove_registered_files
) == SIG_ERR
||
98 SIGNAL(SIGINT
, remove_registered_files
) == SIG_ERR
||
99 SIGNAL(SIGQUIT
, remove_registered_files
) == SIG_ERR
||
100 SIGNAL(SIGTERM
, remove_registered_files
) == SIG_ERR
||
101 SIGNAL(SIGILL
, remove_registered_files
) == SIG_ERR
||
103 SIGNAL(SIGBUS
, remove_registered_files
) == SIG_ERR
||
105 SIGNAL(SIGSEGV
, remove_registered_files
) == SIG_ERR
) {