Fix sigevent namespace (bug 21543).
[glibc.git] / signal / signal.h
blob21d628dbd26e6ef8d9a3217a662ba28bd992e375
1 /* Copyright (C) 1991-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
19 * ISO C99 Standard: 7.14 Signal handling <signal.h>
22 #ifndef _SIGNAL_H
23 #define _SIGNAL_H
25 #include <features.h>
27 __BEGIN_DECLS
29 #include <bits/types.h>
30 #include <bits/signum.h>
32 #include <bits/types/sig_atomic_t.h>
34 #if defined __USE_POSIX
35 #include <bits/types/sigset_t.h>
36 #endif
38 #if defined __USE_XOPEN || defined __USE_XOPEN2K
39 # ifndef __pid_t_defined
40 typedef __pid_t pid_t;
41 # define __pid_t_defined
42 #endif
43 #ifdef __USE_XOPEN
44 # endif
45 # ifndef __uid_t_defined
46 typedef __uid_t uid_t;
47 # define __uid_t_defined
48 # endif
49 #endif /* Unix98 */
51 #ifdef __USE_POSIX199309
52 /* We need `struct timespec' later on. */
53 # include <bits/types/struct_timespec.h>
54 #endif
56 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
57 # include <bits/types/siginfo_t.h>
58 # include <bits/siginfo-consts.h>
59 #endif
61 #ifdef __USE_POSIX199309
62 # include <bits/types/sigevent_t.h>
63 # include <bits/sigevent-consts.h>
64 #endif
67 /* Type of a signal handler. */
68 typedef void (*__sighandler_t) (int);
70 /* The X/Open definition of `signal' specifies the SVID semantic. Use
71 the additional function `sysv_signal' when X/Open compatibility is
72 requested. */
73 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
74 __THROW;
75 #ifdef __USE_GNU
76 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
77 __THROW;
78 #endif
80 /* Set the handler for the signal SIG to HANDLER, returning the old
81 handler, or SIG_ERR on error.
82 By default `signal' has the BSD semantic. */
83 #ifdef __USE_MISC
84 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
85 __THROW;
86 #else
87 /* Make sure the used `signal' implementation is the SVID version. */
88 # ifdef __REDIRECT_NTH
89 extern __sighandler_t __REDIRECT_NTH (signal,
90 (int __sig, __sighandler_t __handler),
91 __sysv_signal);
92 # else
93 # define signal __sysv_signal
94 # endif
95 #endif
97 #if defined __USE_XOPEN && !defined __USE_XOPEN2K8
98 /* The X/Open definition of `signal' conflicts with the BSD version.
99 So they defined another function `bsd_signal'. */
100 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
101 __THROW;
102 #endif
104 /* Send signal SIG to process number PID. If PID is zero,
105 send SIG to all processes in the current process's process group.
106 If PID is < -1, send SIG to all processes in process group - PID. */
107 #ifdef __USE_POSIX
108 extern int kill (__pid_t __pid, int __sig) __THROW;
109 #endif /* Use POSIX. */
111 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
112 /* Send SIG to all processes in process group PGRP.
113 If PGRP is zero, send SIG to all processes in
114 the current process's process group. */
115 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
116 #endif /* Use misc || X/Open Unix. */
118 /* Raise signal SIG, i.e., send SIG to yourself. */
119 extern int raise (int __sig) __THROW;
121 #ifdef __USE_MISC
122 /* SVID names for the same things. */
123 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
124 __THROW;
125 extern int gsignal (int __sig) __THROW;
126 #endif /* Use misc. */
128 #ifdef __USE_XOPEN2K8
129 /* Print a message describing the meaning of the given signal number. */
130 extern void psignal (int __sig, const char *__s);
132 /* Print a message describing the meaning of the given signal information. */
133 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
134 #endif /* POSIX 2008. */
138 /* The `sigpause' function in X/Open defines the argument as the
139 signal number. This requires redirecting to another function
140 because the default version in glibc uses an old BSD interface.
142 This function is a cancellation point and therefore not marked with
143 __THROW. */
145 #ifdef __USE_XOPEN
146 # ifdef __GNUC__
147 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
148 # else
149 extern int __sigpause (int __sig_or_mask, int __is_sig);
150 /* Remove a signal from the signal mask and suspend the process. */
151 # define sigpause(sig) __sigpause ((sig), 1)
152 # endif
153 #endif
156 #ifdef __USE_MISC
157 /* None of the following functions should be used anymore. They are here
158 only for compatibility. A single word (`int') is not guaranteed to be
159 enough to hold a complete signal mask and therefore these functions
160 simply do not work in many situations. Use `sigprocmask' instead. */
162 /* Compute mask for signal SIG. */
163 # define sigmask(sig) ((int)(1u << ((sig) - 1)))
165 /* Block signals in MASK, returning the old mask. */
166 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
168 /* Set the mask of blocked signals to MASK, returning the old mask. */
169 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
171 /* Return currently selected signal mask. */
172 extern int siggetmask (void) __THROW __attribute_deprecated__;
173 #endif /* Use misc. */
176 #ifdef __USE_MISC
177 # define NSIG _NSIG
178 #endif
180 #ifdef __USE_GNU
181 typedef __sighandler_t sighandler_t;
182 #endif
184 /* 4.4 BSD uses the name `sig_t' for this. */
185 #ifdef __USE_MISC
186 typedef __sighandler_t sig_t;
187 #endif
189 #ifdef __USE_POSIX
191 /* Clear all signals from SET. */
192 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
194 /* Set all signals in SET. */
195 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
197 /* Add SIGNO to SET. */
198 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
200 /* Remove SIGNO from SET. */
201 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
203 /* Return 1 if SIGNO is in SET, 0 if not. */
204 extern int sigismember (const sigset_t *__set, int __signo)
205 __THROW __nonnull ((1));
207 # ifdef __USE_GNU
208 /* Return non-empty value is SET is not empty. */
209 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
211 /* Build new signal set by combining the two inputs set using logical AND. */
212 extern int sigandset (sigset_t *__set, const sigset_t *__left,
213 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
215 /* Build new signal set by combining the two inputs set using logical OR. */
216 extern int sigorset (sigset_t *__set, const sigset_t *__left,
217 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
218 # endif /* GNU */
220 /* Get the system-specific definitions of `struct sigaction'
221 and the `SA_*' and `SIG_*'. constants. */
222 # include <bits/sigaction.h>
224 /* Get and/or change the set of blocked signals. */
225 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
226 sigset_t *__restrict __oset) __THROW;
228 /* Change the set of blocked signals to SET,
229 wait until a signal arrives, and restore the set of blocked signals.
231 This function is a cancellation point and therefore not marked with
232 __THROW. */
233 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
235 /* Get and/or set the action for signal SIG. */
236 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
237 struct sigaction *__restrict __oact) __THROW;
239 /* Put in SET all signals that are blocked and waiting to be delivered. */
240 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
243 /* Select any of pending signals from SET or wait for any to arrive.
245 This function is a cancellation point and therefore not marked with
246 __THROW. */
247 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
248 __nonnull ((1, 2));
250 # ifdef __USE_POSIX199309
251 /* Select any of pending signals from SET and place information in INFO.
253 This function is a cancellation point and therefore not marked with
254 __THROW. */
255 extern int sigwaitinfo (const sigset_t *__restrict __set,
256 siginfo_t *__restrict __info) __nonnull ((1));
258 /* Select any of pending signals from SET and place information in INFO.
259 Wait the time specified by TIMEOUT if no signal is pending.
261 This function is a cancellation point and therefore not marked with
262 __THROW. */
263 extern int sigtimedwait (const sigset_t *__restrict __set,
264 siginfo_t *__restrict __info,
265 const struct timespec *__restrict __timeout)
266 __nonnull ((1));
268 /* Send signal SIG to the process PID. Associate data in VAL with the
269 signal. */
270 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
271 __THROW;
272 # endif /* Use POSIX 199306. */
274 #endif /* Use POSIX. */
276 #ifdef __USE_MISC
278 /* Names of the signals. This variable exists only for compatibility.
279 Use `strsignal' instead (see <string.h>). */
280 extern const char *const _sys_siglist[_NSIG];
281 extern const char *const sys_siglist[_NSIG];
284 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
285 # include <bits/sigcontext.h>
287 /* Restore the state saved in SCP. */
288 extern int sigreturn (struct sigcontext *__scp) __THROW;
290 #endif /* Use misc. */
293 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
294 # define __need_size_t
295 # include <stddef.h>
297 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
298 (causing them to fail with EINTR); if INTERRUPT is zero, make system
299 calls be restarted after signal SIG. */
300 extern int siginterrupt (int __sig, int __interrupt) __THROW;
302 # include <bits/sigstack.h>
303 # include <bits/types/stack_t.h>
304 # include <bits/ss_flags.h>
305 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
306 /* This will define `ucontext_t' and `mcontext_t'. */
307 # include <sys/ucontext.h>
308 # endif
310 /* Alternate signal handler stack interface.
311 This interface should always be preferred over `sigstack'. */
312 extern int sigaltstack (const struct sigaltstack *__restrict __ss,
313 struct sigaltstack *__restrict __oss) __THROW;
315 #endif /* Use POSIX.1-2008 or X/Open Unix. */
317 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
318 || defined __USE_MISC)
319 # include <bits/types/struct_sigstack.h>
320 #endif
322 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
323 || defined __USE_MISC)
324 /* Run signals handlers on the stack specified by SS (if not NULL).
325 If OSS is not NULL, it is filled in with the old signal stack status.
326 This interface is obsolete and on many platform not implemented. */
327 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
328 __THROW __attribute_deprecated__;
329 #endif
331 #ifdef __USE_XOPEN_EXTENDED
332 /* Simplified interface for signal management. */
334 /* Add SIG to the calling process' signal mask. */
335 extern int sighold (int __sig) __THROW;
337 /* Remove SIG from the calling process' signal mask. */
338 extern int sigrelse (int __sig) __THROW;
340 /* Set the disposition of SIG to SIG_IGN. */
341 extern int sigignore (int __sig) __THROW;
343 /* Set the disposition of SIG. */
344 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
345 #endif
347 #if defined __USE_POSIX199506 || defined __USE_UNIX98
348 /* Some of the functions for handling signals in threaded programs must
349 be defined here. */
350 # include <bits/pthreadtypes.h>
351 # include <bits/sigthread.h>
352 #endif /* use Unix98 */
354 /* The following functions are used internally in the C library and in
355 other code which need deep insights. */
357 /* Return number of available real-time signal with highest priority. */
358 extern int __libc_current_sigrtmin (void) __THROW;
359 /* Return number of available real-time signal with lowest priority. */
360 extern int __libc_current_sigrtmax (void) __THROW;
362 __END_DECLS
364 #endif /* not signal.h */