]>
diplodocus.org Git - nmh/blob - sbr/signals.c
31253e94e96db7e763fbb79666b1a29d472b89f2
2 * signals.c -- general signals interface for nmh
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
10 #include <h/signals.h>
13 extern void remove_registered_files(int);
17 * A version of the function `signal' that uses reliable
18 * signals, if the machine supports them. Also, (assuming
19 * OS support), it restarts interrupted system calls for all
20 * signals except SIGALRM.
22 * Since we are now assuming POSIX signal support everywhere, we always
23 * use reliable signals.
27 SIGNAL (int sig
, SIGNAL_HANDLER func
)
29 struct sigaction act
, oact
;
31 act
.sa_handler
= func
;
32 sigemptyset(&act
.sa_mask
);
37 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
41 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
44 if (sigaction(sig
, &act
, &oact
) < 0)
46 return (oact
.sa_handler
);
51 * A version of the function `signal' that will set
52 * the handler of `sig' to `func' if the signal is
53 * not currently set to SIG_IGN. Also uses reliable
54 * signals if available.
57 SIGNAL2 (int sig
, SIGNAL_HANDLER func
)
59 struct sigaction act
, oact
;
61 if (sigaction(sig
, NULL
, &oact
) < 0)
63 if (oact
.sa_handler
!= SIG_IGN
) {
64 act
.sa_handler
= func
;
65 sigemptyset(&act
.sa_mask
);
70 act
.sa_flags
|= SA_INTERRUPT
; /* SunOS */
74 act
.sa_flags
|= SA_RESTART
; /* SVR4, BSD4.4 */
77 if (sigaction(sig
, &act
, &oact
) < 0)
80 return (oact
.sa_handler
);
85 * For use by nmh_init().
88 setup_signal_handlers() {
90 * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
91 * files when the user terminates the process early. And also a
92 * few other common signals that can be thrown due to bugs, stack
96 if (SIGNAL(SIGHUP
, remove_registered_files
) == SIG_ERR
||
97 SIGNAL(SIGINT
, remove_registered_files
) == SIG_ERR
||
98 SIGNAL(SIGQUIT
, remove_registered_files
) == SIG_ERR
||
99 SIGNAL(SIGTERM
, remove_registered_files
) == SIG_ERR
||
100 SIGNAL(SIGILL
, remove_registered_files
) == SIG_ERR
||
102 SIGNAL(SIGBUS
, remove_registered_files
) == SIG_ERR
||
104 SIGNAL(SIGSEGV
, remove_registered_files
) == SIG_ERR
) {