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 ** A version of the function `signal' that uses reliable
15 ** signals, if the machine supports them. Also, (assuming
16 ** OS support), it restarts interrupted system calls for all
17 ** signals except SIGALRM.
19 ** Since we are now assuming POSIX signal support everywhere, we always
20 ** use reliable signals.
24 SIGNAL(int sig, SIGNAL_HANDLER func)
26 struct sigaction act, oact;
28 act.sa_handler = func;
29 sigemptyset(&act.sa_mask);
34 act.sa_flags |= SA_INTERRUPT; /* SunOS */
38 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
41 if (sigaction(sig, &act, &oact) < 0)
43 return (oact.sa_handler);
48 ** A version of the function `signal' that will set
49 ** the handler of `sig' to `func' if the signal is
50 ** not currently set to SIG_IGN. Also uses reliable
51 ** signals if available.
54 SIGNAL2(int sig, SIGNAL_HANDLER func)
56 struct sigaction act, oact;
58 if (sigaction(sig, NULL, &oact) < 0)
60 if (oact.sa_handler != SIG_IGN) {
61 act.sa_handler = func;
62 sigemptyset(&act.sa_mask);
67 act.sa_flags |= SA_INTERRUPT; /* SunOS */
71 act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */
74 if (sigaction(sig, &act, &oact) < 0)
77 return (oact.sa_handler);