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>
14 SIGPROCMASK (int how, const sigset_t *set, sigset_t *oset)
17 return sigprocmask(how, set, oset);
22 *oset = sigblock(*set);
26 *oset = sigsetmask(*oset);
27 sigsetmask(*oset & ~(*set));
30 *oset = sigsetmask(*set);
33 adios(NULL, "unknown flag in SIGPROCMASK");
43 * A version of the function `signal' that uses reliable
44 * signals, if the machine supports them. Also, (assuming
45 * OS support), it restarts interrupted system calls for all
46 * signals except SIGALRM.
50 SIGNAL (int sig, SIGNAL_HANDLER func)
53 struct sigaction act, oact;
55 act.sa_handler = func;
56 sigemptyset(&act.sa_mask);
61 act.sa_flags |= SA_INTERRUPT; /* SunOS */
65 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
68 if (sigaction(sig, &act, &oact) < 0)
70 return (oact.sa_handler);
72 return signal (sig, func);
78 * A version of the function `signal' that will set
79 * the handler of `sig' to `func' if the signal is
80 * not currently set to SIG_IGN. Also uses reliable
81 * signals if available.
84 SIGNAL2 (int sig, SIGNAL_HANDLER func)
87 struct sigaction act, oact;
89 if (sigaction(sig, NULL, &oact) < 0)
91 if (oact.sa_handler != SIG_IGN) {
92 act.sa_handler = func;
93 sigemptyset(&act.sa_mask);
98 act.sa_flags |= SA_INTERRUPT; /* SunOS */
102 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
105 if (sigaction(sig, &act, &oact) < 0)
108 return (oact.sa_handler);
110 SIGNAL_HANDLER ofunc;
112 if ((ofunc = signal (sig, SIG_IGN)) != SIG_IGN)