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>
15 * A version of the function `signal' that uses reliable
16 * signals, if the machine supports them. Also, (assuming
17 * OS support), it restarts interrupted system calls for all
18 * signals except SIGALRM.
20 * Since we are now assuming POSIX signal support everywhere, we always
21 * use reliable signals.
25 SIGNAL (int sig, SIGNAL_HANDLER func)
27 struct sigaction act, oact;
29 act.sa_handler = func;
30 sigemptyset(&act.sa_mask);
35 act.sa_flags |= SA_INTERRUPT; /* SunOS */
39 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
42 if (sigaction(sig, &act, &oact) < 0)
44 return (oact.sa_handler);
49 * A version of the function `signal' that will set
50 * the handler of `sig' to `func' if the signal is
51 * not currently set to SIG_IGN. Also uses reliable
52 * signals if available.
55 SIGNAL2 (int sig, SIGNAL_HANDLER func)
57 struct sigaction act, oact;
59 if (sigaction(sig, NULL, &oact) < 0)
61 if (oact.sa_handler != SIG_IGN) {
62 act.sa_handler = func;
63 sigemptyset(&act.sa_mask);
68 act.sa_flags |= SA_INTERRUPT; /* SunOS */
72 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
75 if (sigaction(sig, &act, &oact) < 0)
78 return (oact.sa_handler);