Update copyright dates with scripts/update-copyrights.
[glibc.git] / signal / signal.h
blob2c7f9e104333ca51f5dea4b1025a780bfc92cda4
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
24 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
25 # define _SIGNAL_H
26 #endif
28 #include <features.h>
30 __BEGIN_DECLS
32 #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
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
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
54 #ifdef _SIGNAL_H
56 #include <bits/types.h>
57 #include <bits/signum.h>
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 */
72 #ifdef __USE_POSIX199309
73 /* We need `struct timespec' later on. */
74 # include <bits/types/struct_timespec.h>
75 #endif
77 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
78 /* Get the `siginfo_t' type plus the needed symbols. */
79 # include <bits/siginfo.h>
80 #endif
83 /* Type of a signal handler. */
84 typedef void (*__sighandler_t) (int);
86 /* The X/Open definition of `signal' specifies the SVID semantic. Use
87 the additional function `sysv_signal' when X/Open compatibility is
88 requested. */
89 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
90 __THROW;
91 #ifdef __USE_GNU
92 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
93 __THROW;
94 #endif
96 /* Set the handler for the signal SIG to HANDLER, returning the old
97 handler, or SIG_ERR on error.
98 By default `signal' has the BSD semantic. */
99 __BEGIN_NAMESPACE_STD
100 #ifdef __USE_MISC
101 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
102 __THROW;
103 #else
104 /* Make sure the used `signal' implementation is the SVID version. */
105 # ifdef __REDIRECT_NTH
106 extern __sighandler_t __REDIRECT_NTH (signal,
107 (int __sig, __sighandler_t __handler),
108 __sysv_signal);
109 # else
110 # define signal __sysv_signal
111 # endif
112 #endif
113 __END_NAMESPACE_STD
115 #ifdef __USE_XOPEN
116 /* The X/Open definition of `signal' conflicts with the BSD version.
117 So they defined another function `bsd_signal'. */
118 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
119 __THROW;
120 #endif
122 /* Send signal SIG to process number PID. If PID is zero,
123 send SIG to all processes in the current process's process group.
124 If PID is < -1, send SIG to all processes in process group - PID. */
125 #ifdef __USE_POSIX
126 extern int kill (__pid_t __pid, int __sig) __THROW;
127 #endif /* Use POSIX. */
129 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
130 /* Send SIG to all processes in process group PGRP.
131 If PGRP is zero, send SIG to all processes in
132 the current process's process group. */
133 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
134 #endif /* Use misc || X/Open Unix. */
136 __BEGIN_NAMESPACE_STD
137 /* Raise signal SIG, i.e., send SIG to yourself. */
138 extern int raise (int __sig) __THROW;
139 __END_NAMESPACE_STD
141 #ifdef __USE_MISC
142 /* SVID names for the same things. */
143 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
144 __THROW;
145 extern int gsignal (int __sig) __THROW;
146 #endif /* Use misc. */
148 #ifdef __USE_XOPEN2K8
149 /* Print a message describing the meaning of the given signal number. */
150 extern void psignal (int __sig, const char *__s);
152 /* Print a message describing the meaning of the given signal information. */
153 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
154 #endif /* POSIX 2008. */
158 /* The `sigpause' function in X/Open defines the argument as the
159 signal number. This requires redirecting to another function
160 because the default version in glibc uses an old BSD interface.
162 This function is a cancellation point and therefore not marked with
163 __THROW. */
165 #ifdef __USE_XOPEN
166 # ifdef __GNUC__
167 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
168 # else
169 extern int __sigpause (int __sig_or_mask, int __is_sig);
170 /* Remove a signal from the signal mask and suspend the process. */
171 # define sigpause(sig) __sigpause ((sig), 1)
172 # endif
173 #endif
176 #ifdef __USE_MISC
177 /* None of the following functions should be used anymore. They are here
178 only for compatibility. A single word (`int') is not guaranteed to be
179 enough to hold a complete signal mask and therefore these functions
180 simply do not work in many situations. Use `sigprocmask' instead. */
182 /* Compute mask for signal SIG. */
183 # define sigmask(sig) __sigmask(sig)
185 /* Block signals in MASK, returning the old mask. */
186 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
188 /* Set the mask of blocked signals to MASK, returning the old mask. */
189 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
191 /* Return currently selected signal mask. */
192 extern int siggetmask (void) __THROW __attribute_deprecated__;
193 #endif /* Use misc. */
196 #ifdef __USE_MISC
197 # define NSIG _NSIG
198 #endif
200 #ifdef __USE_GNU
201 typedef __sighandler_t sighandler_t;
202 #endif
204 /* 4.4 BSD uses the name `sig_t' for this. */
205 #ifdef __USE_MISC
206 typedef __sighandler_t sig_t;
207 #endif
209 #ifdef __USE_POSIX
211 /* Clear all signals from SET. */
212 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
214 /* Set all signals in SET. */
215 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
217 /* Add SIGNO to SET. */
218 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
220 /* Remove SIGNO from SET. */
221 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
223 /* Return 1 if SIGNO is in SET, 0 if not. */
224 extern int sigismember (const sigset_t *__set, int __signo)
225 __THROW __nonnull ((1));
227 # ifdef __USE_GNU
228 /* Return non-empty value is SET is not empty. */
229 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
231 /* Build new signal set by combining the two inputs set using logical AND. */
232 extern int sigandset (sigset_t *__set, const sigset_t *__left,
233 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
235 /* Build new signal set by combining the two inputs set using logical OR. */
236 extern int sigorset (sigset_t *__set, const sigset_t *__left,
237 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
238 # endif /* GNU */
240 /* Get the system-specific definitions of `struct sigaction'
241 and the `SA_*' and `SIG_*'. constants. */
242 # include <bits/sigaction.h>
244 /* Get and/or change the set of blocked signals. */
245 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
246 sigset_t *__restrict __oset) __THROW;
248 /* Change the set of blocked signals to SET,
249 wait until a signal arrives, and restore the set of blocked signals.
251 This function is a cancellation point and therefore not marked with
252 __THROW. */
253 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
255 /* Get and/or set the action for signal SIG. */
256 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
257 struct sigaction *__restrict __oact) __THROW;
259 /* Put in SET all signals that are blocked and waiting to be delivered. */
260 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
263 /* Select any of pending signals from SET or wait for any to arrive.
265 This function is a cancellation point and therefore not marked with
266 __THROW. */
267 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
268 __nonnull ((1, 2));
270 # ifdef __USE_POSIX199309
271 /* Select any of pending signals from SET and place information in INFO.
273 This function is a cancellation point and therefore not marked with
274 __THROW. */
275 extern int sigwaitinfo (const sigset_t *__restrict __set,
276 siginfo_t *__restrict __info) __nonnull ((1));
278 /* Select any of pending signals from SET and place information in INFO.
279 Wait the time specified by TIMEOUT if no signal is pending.
281 This function is a cancellation point and therefore not marked with
282 __THROW. */
283 extern int sigtimedwait (const sigset_t *__restrict __set,
284 siginfo_t *__restrict __info,
285 const struct timespec *__restrict __timeout)
286 __nonnull ((1));
288 /* Send signal SIG to the process PID. Associate data in VAL with the
289 signal. */
290 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
291 __THROW;
292 # endif /* Use POSIX 199306. */
294 #endif /* Use POSIX. */
296 #ifdef __USE_MISC
298 /* Names of the signals. This variable exists only for compatibility.
299 Use `strsignal' instead (see <string.h>). */
300 extern const char *const _sys_siglist[_NSIG];
301 extern const char *const sys_siglist[_NSIG];
304 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
305 # include <bits/sigcontext.h>
307 /* Restore the state saved in SCP. */
308 extern int sigreturn (struct sigcontext *__scp) __THROW;
310 #endif /* Use misc. */
313 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
314 # define __need_size_t
315 # include <stddef.h>
317 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
318 (causing them to fail with EINTR); if INTERRUPT is zero, make system
319 calls be restarted after signal SIG. */
320 extern int siginterrupt (int __sig, int __interrupt) __THROW;
322 # include <bits/sigstack.h>
323 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
324 /* This will define `ucontext_t' and `mcontext_t'. */
325 # include <sys/ucontext.h>
326 # endif
328 /* Run signals handlers on the stack specified by SS (if not NULL).
329 If OSS is not NULL, it is filled in with the old signal stack status.
330 This interface is obsolete and on many platform not implemented. */
331 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
332 __THROW __attribute_deprecated__;
334 /* Alternate signal handler stack interface.
335 This interface should always be preferred over `sigstack'. */
336 extern int sigaltstack (const struct sigaltstack *__restrict __ss,
337 struct sigaltstack *__restrict __oss) __THROW;
339 #endif /* Use POSIX.1-2008 or X/Open Unix. */
341 #ifdef __USE_XOPEN_EXTENDED
342 /* Simplified interface for signal management. */
344 /* Add SIG to the calling process' signal mask. */
345 extern int sighold (int __sig) __THROW;
347 /* Remove SIG from the calling process' signal mask. */
348 extern int sigrelse (int __sig) __THROW;
350 /* Set the disposition of SIG to SIG_IGN. */
351 extern int sigignore (int __sig) __THROW;
353 /* Set the disposition of SIG. */
354 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
355 #endif
357 #if defined __USE_POSIX199506 || defined __USE_UNIX98
358 /* Some of the functions for handling signals in threaded programs must
359 be defined here. */
360 # include <bits/pthreadtypes.h>
361 # include <bits/sigthread.h>
362 #endif /* use Unix98 */
364 /* The following functions are used internally in the C library and in
365 other code which need deep insights. */
367 /* Return number of available real-time signal with highest priority. */
368 extern int __libc_current_sigrtmin (void) __THROW;
369 /* Return number of available real-time signal with lowest priority. */
370 extern int __libc_current_sigrtmax (void) __THROW;
372 #endif /* signal.h */
374 __END_DECLS
376 #endif /* not signal.h */