stop touching the wrong stamp filename after configuring
[debian/sudo] / sigaction.c
1 /*
2  * Copyright (c) 2001-2005 Todd C. Miller <Todd.Miller@courtesan.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  *
16  * Sponsored in part by the Defense Advanced Research Projects
17  * Agency (DARPA) and Air Force Research Laboratory, Air Force
18  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
19  */
20
21 #include <signal.h>
22 #include <errno.h>
23
24 #include <compat.h>
25
26 int
27 sigaction(signo, sa, osa)
28     int signo;
29     const sigaction_t *sa;
30     sigaction_t *osa;
31 {
32     sigaction_t nsa;
33     int error;
34
35     /* We must reverse SV_INTERRUPT since it is the opposite of SA_RESTART */
36     if (sa) {
37         nsa = *sa;
38         nsa.sa_flags ^= SV_INTERRUPT;
39         sa = &nsa;
40     }
41
42     error = sigvec(signo, sa, osa);
43     if (!error && osa)
44         osa->sa_flags ^= SV_INTERRUPT;          /* flip SV_INTERRUPT as above */
45
46     return(error);
47 }
48
49 int
50 sigemptyset(set)
51     sigset_t *set;
52 {
53
54     *set = 0;
55     return(0);
56 }
57
58 int
59 sigfillset(set)
60     sigset_t *set;
61 {
62
63     *set = ~0;;
64     return(0);
65 }
66
67 int
68 sigaddset(set, signo)
69     sigset_t *set;
70     int signo;
71 {
72
73     if (signo <= 0 || signo >= NSIG) {
74         errno = EINVAL;
75         return(-1);
76     }
77
78     SET(*set, sigmask(signo));
79     return(0);
80 }
81
82 int
83 sigdelset(set, signo)
84     sigset_t *set;
85     int signo;
86 {
87
88     if (signo <= 0 || signo >= NSIG) {
89         errno = EINVAL;
90         return(-1);
91     }
92
93     CLR(*set, sigmask(signo));
94     return(0);
95 }
96
97 int
98 sigismember(set, signo)
99     sigset_t *set;
100     int signo;
101 {
102
103     return(ISSET(*set, sigmask(signo)));
104 }
105
106 int
107 sigprocmask(how, set, oset)
108     int how;
109     const sigset_t *set;
110     sigset_t *oset;
111 {
112     int mask;
113
114     /* If 'set' is NULL the user just wants the current signal mask. */
115     if (set == 0)
116         mask = sigblock(0);
117     else
118         switch (how) {
119             case SIG_BLOCK:
120                 mask = sigblock(*set);
121                 break;
122             case SIG_UNBLOCK:
123                 mask = sigsetmask(~*set);
124                 break;
125             case SIG_SETMASK:
126                 mask = sigsetmask(*set);
127                 break;
128             default:
129                 return(-1);
130         }
131
132     if (mask == -1)
133         return(-1);
134     if (oset)
135         *oset = mask;
136     return(0);
137 }