1 | /* Copyright (C) 1991-2004,2007,2009,2010,2012 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ |
17 | |
18 | /* |
19 | * ISO C99 Standard: 7.14 Signal handling <signal.h> |
20 | */ |
21 | |
22 | #ifndef _SIGNAL_H |
23 | |
24 | #if !defined __need_sig_atomic_t && !defined __need_sigset_t |
25 | # define _SIGNAL_H |
26 | #endif |
27 | |
28 | #include <features.h> |
29 | |
30 | __BEGIN_DECLS |
31 | |
32 | #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */ |
33 | |
34 | /* An integral type that can be modified atomically, without the |
35 | possibility of a signal arriving in the middle of the operation. */ |
36 | #if defined __need_sig_atomic_t || defined _SIGNAL_H |
37 | # ifndef __sig_atomic_t_defined |
38 | # define __sig_atomic_t_defined |
39 | __BEGIN_NAMESPACE_STD |
40 | typedef __sig_atomic_t sig_atomic_t; |
41 | __END_NAMESPACE_STD |
42 | # endif |
43 | # undef __need_sig_atomic_t |
44 | #endif |
45 | |
46 | #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX) |
47 | # ifndef __sigset_t_defined |
48 | # define __sigset_t_defined |
49 | typedef __sigset_t sigset_t; |
50 | # endif |
51 | # undef __need_sigset_t |
52 | #endif |
53 | |
54 | #ifdef _SIGNAL_H |
55 | |
56 | #include <bits/types.h> |
57 | #include <bits/signum.h> |
58 | |
59 | #if defined __USE_XOPEN || defined __USE_XOPEN2K |
60 | # ifndef __pid_t_defined |
61 | typedef __pid_t pid_t; |
62 | # define __pid_t_defined |
63 | #endif |
64 | #ifdef __USE_XOPEN |
65 | # endif |
66 | # ifndef __uid_t_defined |
67 | typedef __uid_t uid_t; |
68 | # define __uid_t_defined |
69 | # endif |
70 | #endif /* Unix98 */ |
71 | |
72 | #ifdef __USE_POSIX199309 |
73 | /* We need `struct timespec' later on. */ |
74 | # define __need_timespec |
75 | # include <time.h> |
76 | |
77 | /* Get the `siginfo_t' type plus the needed symbols. */ |
78 | # include <bits/siginfo.h> |
79 | #endif |
80 | |
81 | |
82 | /* Type of a signal handler. */ |
83 | typedef void (*__sighandler_t) (int); |
84 | |
85 | /* The X/Open definition of `signal' specifies the SVID semantic. Use |
86 | the additional function `sysv_signal' when X/Open compatibility is |
87 | requested. */ |
88 | extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler) |
89 | __THROW; |
90 | #ifdef __USE_GNU |
91 | extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler) |
92 | __THROW; |
93 | #endif |
94 | |
95 | /* Set the handler for the signal SIG to HANDLER, returning the old |
96 | handler, or SIG_ERR on error. |
97 | By default `signal' has the BSD semantic. */ |
98 | __BEGIN_NAMESPACE_STD |
99 | #ifdef __USE_BSD |
100 | extern __sighandler_t signal (int __sig, __sighandler_t __handler) |
101 | __THROW; |
102 | #else |
103 | /* Make sure the used `signal' implementation is the SVID version. */ |
104 | # ifdef __REDIRECT_NTH |
105 | extern __sighandler_t __REDIRECT_NTH (signal, |
106 | (int __sig, __sighandler_t __handler), |
107 | __sysv_signal); |
108 | # else |
109 | # define signal __sysv_signal |
110 | # endif |
111 | #endif |
112 | __END_NAMESPACE_STD |
113 | |
114 | #ifdef __USE_XOPEN |
115 | /* The X/Open definition of `signal' conflicts with the BSD version. |
116 | So they defined another function `bsd_signal'. */ |
117 | extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) |
118 | __THROW; |
119 | #endif |
120 | |
121 | /* Send signal SIG to process number PID. If PID is zero, |
122 | send SIG to all processes in the current process's process group. |
123 | If PID is < -1, send SIG to all processes in process group - PID. */ |
124 | #ifdef __USE_POSIX |
125 | extern int kill (__pid_t __pid, int __sig) __THROW; |
126 | #endif /* Use POSIX. */ |
127 | |
128 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
129 | /* Send SIG to all processes in process group PGRP. |
130 | If PGRP is zero, send SIG to all processes in |
131 | the current process's process group. */ |
132 | extern int killpg (__pid_t __pgrp, int __sig) __THROW; |
133 | #endif /* Use BSD || X/Open Unix. */ |
134 | |
135 | __BEGIN_NAMESPACE_STD |
136 | /* Raise signal SIG, i.e., send SIG to yourself. */ |
137 | extern int raise (int __sig) __THROW; |
138 | __END_NAMESPACE_STD |
139 | |
140 | #ifdef __USE_SVID |
141 | /* SVID names for the same things. */ |
142 | extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) |
143 | __THROW; |
144 | extern int gsignal (int __sig) __THROW; |
145 | #endif /* Use SVID. */ |
146 | |
147 | #if defined __USE_MISC || defined __USE_XOPEN2K |
148 | /* Print a message describing the meaning of the given signal number. */ |
149 | extern void psignal (int __sig, const char *__s); |
150 | #endif /* Use misc or POSIX 2008. */ |
151 | |
152 | #ifdef __USE_XOPEN2K |
153 | /* Print a message describing the meaning of the given signal information. */ |
154 | extern void psiginfo (const siginfo_t *__pinfo, const char *__s); |
155 | #endif /* POSIX 2008. */ |
156 | |
157 | |
158 | |
159 | /* The `sigpause' function has two different interfaces. The original |
160 | BSD definition defines the argument as a mask of the signal, while |
161 | the more modern interface in X/Open defines it as the signal |
162 | number. We go with the BSD version unless the user explicitly |
163 | selects the X/Open version. |
164 | |
165 | This function is a cancellation point and therefore not marked with |
166 | __THROW. */ |
167 | extern int __sigpause (int __sig_or_mask, int __is_sig); |
168 | |
169 | #ifdef __FAVOR_BSD |
170 | /* Set the mask of blocked signals to MASK, |
171 | wait for a signal to arrive, and then restore the mask. */ |
172 | extern int sigpause (int __mask) __THROW __attribute_deprecated__; |
173 | #else |
174 | # ifdef __USE_XOPEN |
175 | # ifdef __GNUC__ |
176 | extern int sigpause (int __sig) __asm__ ("__xpg_sigpause" ); |
177 | # else |
178 | /* Remove a signal from the signal mask and suspend the process. */ |
179 | # define sigpause(sig) __sigpause ((sig), 1) |
180 | # endif |
181 | # endif |
182 | #endif |
183 | |
184 | |
185 | #ifdef __USE_BSD |
186 | /* None of the following functions should be used anymore. They are here |
187 | only for compatibility. A single word (`int') is not guaranteed to be |
188 | enough to hold a complete signal mask and therefore these functions |
189 | simply do not work in many situations. Use `sigprocmask' instead. */ |
190 | |
191 | /* Compute mask for signal SIG. */ |
192 | # define sigmask(sig) __sigmask(sig) |
193 | |
194 | /* Block signals in MASK, returning the old mask. */ |
195 | extern int sigblock (int __mask) __THROW __attribute_deprecated__; |
196 | |
197 | /* Set the mask of blocked signals to MASK, returning the old mask. */ |
198 | extern int sigsetmask (int __mask) __THROW __attribute_deprecated__; |
199 | |
200 | /* Return currently selected signal mask. */ |
201 | extern int siggetmask (void) __THROW __attribute_deprecated__; |
202 | #endif /* Use BSD. */ |
203 | |
204 | |
205 | #ifdef __USE_MISC |
206 | # define NSIG _NSIG |
207 | #endif |
208 | |
209 | #ifdef __USE_GNU |
210 | typedef __sighandler_t sighandler_t; |
211 | #endif |
212 | |
213 | /* 4.4 BSD uses the name `sig_t' for this. */ |
214 | #ifdef __USE_BSD |
215 | typedef __sighandler_t sig_t; |
216 | #endif |
217 | |
218 | #ifdef __USE_POSIX |
219 | |
220 | /* Clear all signals from SET. */ |
221 | extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1)); |
222 | |
223 | /* Set all signals in SET. */ |
224 | extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1)); |
225 | |
226 | /* Add SIGNO to SET. */ |
227 | extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1)); |
228 | |
229 | /* Remove SIGNO from SET. */ |
230 | extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1)); |
231 | |
232 | /* Return 1 if SIGNO is in SET, 0 if not. */ |
233 | extern int sigismember (const sigset_t *__set, int __signo) |
234 | __THROW __nonnull ((1)); |
235 | |
236 | # ifdef __USE_GNU |
237 | /* Return non-empty value is SET is not empty. */ |
238 | extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1)); |
239 | |
240 | /* Build new signal set by combining the two inputs set using logical AND. */ |
241 | extern int sigandset (sigset_t *__set, const sigset_t *__left, |
242 | const sigset_t *__right) __THROW __nonnull ((1, 2, 3)); |
243 | |
244 | /* Build new signal set by combining the two inputs set using logical OR. */ |
245 | extern int sigorset (sigset_t *__set, const sigset_t *__left, |
246 | const sigset_t *__right) __THROW __nonnull ((1, 2, 3)); |
247 | # endif /* GNU */ |
248 | |
249 | /* Get the system-specific definitions of `struct sigaction' |
250 | and the `SA_*' and `SIG_*'. constants. */ |
251 | # include <bits/sigaction.h> |
252 | |
253 | /* Get and/or change the set of blocked signals. */ |
254 | extern int sigprocmask (int __how, const sigset_t *__restrict __set, |
255 | sigset_t *__restrict __oset) __THROW; |
256 | |
257 | /* Change the set of blocked signals to SET, |
258 | wait until a signal arrives, and restore the set of blocked signals. |
259 | |
260 | This function is a cancellation point and therefore not marked with |
261 | __THROW. */ |
262 | extern int sigsuspend (const sigset_t *__set) __nonnull ((1)); |
263 | |
264 | /* Get and/or set the action for signal SIG. */ |
265 | extern int sigaction (int __sig, const struct sigaction *__restrict __act, |
266 | struct sigaction *__restrict __oact) __THROW; |
267 | |
268 | /* Put in SET all signals that are blocked and waiting to be delivered. */ |
269 | extern int sigpending (sigset_t *__set) __THROW __nonnull ((1)); |
270 | |
271 | |
272 | /* Select any of pending signals from SET or wait for any to arrive. |
273 | |
274 | This function is a cancellation point and therefore not marked with |
275 | __THROW. */ |
276 | extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig) |
277 | __nonnull ((1, 2)); |
278 | |
279 | # ifdef __USE_POSIX199309 |
280 | /* Select any of pending signals from SET and place information in INFO. |
281 | |
282 | This function is a cancellation point and therefore not marked with |
283 | __THROW. */ |
284 | extern int sigwaitinfo (const sigset_t *__restrict __set, |
285 | siginfo_t *__restrict __info) __nonnull ((1)); |
286 | |
287 | /* Select any of pending signals from SET and place information in INFO. |
288 | Wait the time specified by TIMEOUT if no signal is pending. |
289 | |
290 | This function is a cancellation point and therefore not marked with |
291 | __THROW. */ |
292 | extern int sigtimedwait (const sigset_t *__restrict __set, |
293 | siginfo_t *__restrict __info, |
294 | const struct timespec *__restrict __timeout) |
295 | __nonnull ((1)); |
296 | |
297 | /* Send signal SIG to the process PID. Associate data in VAL with the |
298 | signal. */ |
299 | extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val) |
300 | __THROW; |
301 | # endif /* Use POSIX 199306. */ |
302 | |
303 | #endif /* Use POSIX. */ |
304 | |
305 | #ifdef __USE_BSD |
306 | |
307 | /* Names of the signals. This variable exists only for compatibility. |
308 | Use `strsignal' instead (see <string.h>). */ |
309 | extern const char *const _sys_siglist[_NSIG]; |
310 | extern const char *const sys_siglist[_NSIG]; |
311 | |
312 | /* Structure passed to `sigvec'. */ |
313 | struct sigvec |
314 | { |
315 | __sighandler_t sv_handler; /* Signal handler. */ |
316 | int sv_mask; /* Mask of signals to be blocked. */ |
317 | |
318 | int sv_flags; /* Flags (see below). */ |
319 | # define sv_onstack sv_flags /* 4.2 BSD compatibility. */ |
320 | }; |
321 | |
322 | /* Bits in `sv_flags'. */ |
323 | # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */ |
324 | # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */ |
325 | # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */ |
326 | |
327 | |
328 | /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member |
329 | of VEC. The signals in `sv_mask' will be blocked while the handler runs. |
330 | If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be |
331 | reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL, |
332 | it is filled in with the old information for SIG. */ |
333 | extern int sigvec (int __sig, const struct sigvec *__vec, |
334 | struct sigvec *__ovec) __THROW; |
335 | |
336 | |
337 | /* Get machine-dependent `struct sigcontext' and signal subcodes. */ |
338 | # include <bits/sigcontext.h> |
339 | |
340 | /* Restore the state saved in SCP. */ |
341 | extern int sigreturn (struct sigcontext *__scp) __THROW; |
342 | |
343 | #endif /* use BSD. */ |
344 | |
345 | |
346 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8 |
347 | # define __need_size_t |
348 | # include <stddef.h> |
349 | |
350 | /* If INTERRUPT is nonzero, make signal SIG interrupt system calls |
351 | (causing them to fail with EINTR); if INTERRUPT is zero, make system |
352 | calls be restarted after signal SIG. */ |
353 | extern int siginterrupt (int __sig, int __interrupt) __THROW; |
354 | |
355 | # include <bits/sigstack.h> |
356 | # if defined __USE_XOPEN || defined __USE_XOPEN2K8 |
357 | /* This will define `ucontext_t' and `mcontext_t'. */ |
358 | # include <sys/ucontext.h> |
359 | # endif |
360 | |
361 | /* Run signals handlers on the stack specified by SS (if not NULL). |
362 | If OSS is not NULL, it is filled in with the old signal stack status. |
363 | This interface is obsolete and on many platform not implemented. */ |
364 | extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) |
365 | __THROW __attribute_deprecated__; |
366 | |
367 | /* Alternate signal handler stack interface. |
368 | This interface should always be preferred over `sigstack'. */ |
369 | extern int sigaltstack (const struct sigaltstack *__restrict __ss, |
370 | struct sigaltstack *__restrict __oss) __THROW; |
371 | |
372 | #endif /* use BSD or X/Open Unix. */ |
373 | |
374 | #ifdef __USE_XOPEN_EXTENDED |
375 | /* Simplified interface for signal management. */ |
376 | |
377 | /* Add SIG to the calling process' signal mask. */ |
378 | extern int sighold (int __sig) __THROW; |
379 | |
380 | /* Remove SIG from the calling process' signal mask. */ |
381 | extern int sigrelse (int __sig) __THROW; |
382 | |
383 | /* Set the disposition of SIG to SIG_IGN. */ |
384 | extern int sigignore (int __sig) __THROW; |
385 | |
386 | /* Set the disposition of SIG. */ |
387 | extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW; |
388 | #endif |
389 | |
390 | #if defined __USE_POSIX199506 || defined __USE_UNIX98 |
391 | /* Some of the functions for handling signals in threaded programs must |
392 | be defined here. */ |
393 | # include <bits/pthreadtypes.h> |
394 | # include <bits/sigthread.h> |
395 | #endif /* use Unix98 */ |
396 | |
397 | /* The following functions are used internally in the C library and in |
398 | other code which need deep insights. */ |
399 | |
400 | /* Return number of available real-time signal with highest priority. */ |
401 | extern int __libc_current_sigrtmin (void) __THROW; |
402 | /* Return number of available real-time signal with lowest priority. */ |
403 | extern int __libc_current_sigrtmax (void) __THROW; |
404 | |
405 | #endif /* signal.h */ |
406 | |
407 | __END_DECLS |
408 | |
409 | #endif /* not signal.h */ |
410 | |