remove unused defines in uip/pick.c
[mmh] / sbr / signals.c
1 /*
2 ** signals.c -- general signals interface for nmh
3 **
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.
7 */
8
9 #include <h/mh.h>
10 #include <h/signals.h>
11
12
13 /*
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.
18 **
19 ** Since we are now assuming POSIX signal support everywhere, we always
20 ** use reliable signals.
21 */
22
23 SIGNAL_HANDLER
24 SIGNAL(int sig, SIGNAL_HANDLER func)
25 {
26         struct sigaction act, oact;
27
28         act.sa_handler = func;
29         sigemptyset(&act.sa_mask);
30         act.sa_flags = 0;
31
32         if (sig == SIGALRM) {
33 # ifdef SA_INTERRUPT
34                 act.sa_flags |= SA_INTERRUPT;  /* SunOS */
35 # endif
36         } else {
37 # ifdef SA_RESTART
38                 act.sa_flags |= SA_RESTART;  /* SVR4, BSD4.4 */
39 # endif
40         }
41         if (sigaction(sig, &act, &oact) < 0)
42                 return (SIG_ERR);
43         return (oact.sa_handler);
44 }
45
46
47 /*
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.
52 */
53 SIGNAL_HANDLER
54 SIGNAL2(int sig, SIGNAL_HANDLER func)
55 {
56         struct sigaction act, oact;
57
58         if (sigaction(sig, NULL, &oact) < 0)
59                 return (SIG_ERR);
60         if (oact.sa_handler != SIG_IGN) {
61                 act.sa_handler = func;
62                 sigemptyset(&act.sa_mask);
63                 act.sa_flags = 0;
64
65                 if (sig == SIGALRM) {
66 # ifdef SA_INTERRUPT
67                         act.sa_flags |= SA_INTERRUPT;  /* SunOS */
68 # endif
69                 } else {
70 # ifdef SA_RESTART
71                         act.sa_flags |= SA_RESTART;  /* SVR4, BSD4.4 */
72 # endif
73                 }
74                 if (sigaction(sig, &act, &oact) < 0)
75                         return (SIG_ERR);
76         }
77         return (oact.sa_handler);
78 }