3 * signals.c -- general signals interface for nmh
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/signals.h>
17 SIGPROCMASK (int how, const sigset_t *set, sigset_t *oset)
20 return sigprocmask(how, set, oset);
25 *oset = sigblock(*set);
29 *oset = sigsetmask(*oset);
30 sigsetmask(*oset & ~(*set));
33 *oset = sigsetmask(*set);
36 adios(NULL, "unknown flag in SIGPROCMASK");
46 * A version of the function `signal' that uses reliable
47 * signals, if the machine supports them. Also, (assuming
48 * OS support), it restarts interrupted system calls for all
49 * signals except SIGALRM.
53 SIGNAL (int sig, SIGNAL_HANDLER func)
56 struct sigaction act, oact;
58 act.sa_handler = func;
59 sigemptyset(&act.sa_mask);
64 act.sa_flags |= SA_INTERRUPT; /* SunOS */
68 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
71 if (sigaction(sig, &act, &oact) < 0)
73 return (oact.sa_handler);
75 return signal (sig, func);
81 * A version of the function `signal' that will set
82 * the handler of `sig' to `func' if the signal is
83 * not currently set to SIG_IGN. Also uses reliable
84 * signals if available.
87 SIGNAL2 (int sig, SIGNAL_HANDLER func)
90 struct sigaction act, oact;
92 if (sigaction(sig, NULL, &oact) < 0)
94 if (oact.sa_handler != SIG_IGN) {
95 act.sa_handler = func;
96 sigemptyset(&act.sa_mask);
101 act.sa_flags |= SA_INTERRUPT; /* SunOS */
105 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
108 if (sigaction(sig, &act, &oact) < 0)
111 return (oact.sa_handler);
113 SIGNAL_HANDLER ofunc;
115 if ((ofunc = signal (sig, SIG_IGN)) != SIG_IGN)