1 /* Copyright (C) 1991-2018 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>
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>
38 #if defined __USE_XOPEN || defined __USE_XOPEN2K
39 # ifndef __pid_t_defined
40 typedef __pid_t pid_t
;
41 # define __pid_t_defined
45 # ifndef __uid_t_defined
46 typedef __uid_t uid_t
;
47 # define __uid_t_defined
51 #ifdef __USE_POSIX199309
52 /* We need `struct timespec' later on. */
53 # include <bits/types/struct_timespec.h>
56 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
57 # include <bits/types/siginfo_t.h>
58 # include <bits/siginfo-consts.h>
62 # include <bits/types/sigval_t.h>
65 #ifdef __USE_POSIX199309
66 # include <bits/types/sigevent_t.h>
67 # include <bits/sigevent-consts.h>
71 /* Type of a signal handler. */
72 typedef void (*__sighandler_t
) (int);
74 /* The X/Open definition of `signal' specifies the SVID semantic. Use
75 the additional function `sysv_signal' when X/Open compatibility is
77 extern __sighandler_t
__sysv_signal (int __sig
, __sighandler_t __handler
)
80 extern __sighandler_t
sysv_signal (int __sig
, __sighandler_t __handler
)
84 /* Set the handler for the signal SIG to HANDLER, returning the old
85 handler, or SIG_ERR on error.
86 By default `signal' has the BSD semantic. */
88 extern __sighandler_t
signal (int __sig
, __sighandler_t __handler
)
91 /* Make sure the used `signal' implementation is the SVID version. */
92 # ifdef __REDIRECT_NTH
93 extern __sighandler_t
__REDIRECT_NTH (signal
,
94 (int __sig
, __sighandler_t __handler
),
97 # define signal __sysv_signal
101 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8
102 /* The X/Open definition of `signal' conflicts with the BSD version.
103 So they defined another function `bsd_signal'. */
104 extern __sighandler_t
bsd_signal (int __sig
, __sighandler_t __handler
)
108 /* Send signal SIG to process number PID. If PID is zero,
109 send SIG to all processes in the current process's process group.
110 If PID is < -1, send SIG to all processes in process group - PID. */
112 extern int kill (__pid_t __pid
, int __sig
) __THROW
;
113 #endif /* Use POSIX. */
115 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
116 /* Send SIG to all processes in process group PGRP.
117 If PGRP is zero, send SIG to all processes in
118 the current process's process group. */
119 extern int killpg (__pid_t __pgrp
, int __sig
) __THROW
;
120 #endif /* Use misc || X/Open Unix. */
122 /* Raise signal SIG, i.e., send SIG to yourself. */
123 extern int raise (int __sig
) __THROW
;
126 /* SVID names for the same things. */
127 extern __sighandler_t
ssignal (int __sig
, __sighandler_t __handler
)
129 extern int gsignal (int __sig
) __THROW
;
130 #endif /* Use misc. */
132 #ifdef __USE_XOPEN2K8
133 /* Print a message describing the meaning of the given signal number. */
134 extern void psignal (int __sig
, const char *__s
);
136 /* Print a message describing the meaning of the given signal information. */
137 extern void psiginfo (const siginfo_t
*__pinfo
, const char *__s
);
138 #endif /* POSIX 2008. */
142 /* The `sigpause' function in X/Open defines the argument as the
143 signal number. This requires redirecting to another function
144 because the default version in glibc uses an old BSD interface.
146 This function is a cancellation point and therefore not marked with
149 #ifdef __USE_XOPEN_EXTENDED
151 extern int sigpause (int __sig
) __asm__ ("__xpg_sigpause");
153 extern int __sigpause (int __sig_or_mask
, int __is_sig
);
154 /* Remove a signal from the signal mask and suspend the process. */
155 # define sigpause(sig) __sigpause ((sig), 1)
161 /* None of the following functions should be used anymore. They are here
162 only for compatibility. A single word (`int') is not guaranteed to be
163 enough to hold a complete signal mask and therefore these functions
164 simply do not work in many situations. Use `sigprocmask' instead. */
166 /* Compute mask for signal SIG. */
167 # define sigmask(sig) ((int)(1u << ((sig) - 1)))
169 /* Block signals in MASK, returning the old mask. */
170 extern int sigblock (int __mask
) __THROW __attribute_deprecated__
;
172 /* Set the mask of blocked signals to MASK, returning the old mask. */
173 extern int sigsetmask (int __mask
) __THROW __attribute_deprecated__
;
175 /* Return currently selected signal mask. */
176 extern int siggetmask (void) __THROW __attribute_deprecated__
;
177 #endif /* Use misc. */
185 typedef __sighandler_t sighandler_t
;
188 /* 4.4 BSD uses the name `sig_t' for this. */
190 typedef __sighandler_t sig_t
;
195 /* Clear all signals from SET. */
196 extern int sigemptyset (sigset_t
*__set
) __THROW
__nonnull ((1));
198 /* Set all signals in SET. */
199 extern int sigfillset (sigset_t
*__set
) __THROW
__nonnull ((1));
201 /* Add SIGNO to SET. */
202 extern int sigaddset (sigset_t
*__set
, int __signo
) __THROW
__nonnull ((1));
204 /* Remove SIGNO from SET. */
205 extern int sigdelset (sigset_t
*__set
, int __signo
) __THROW
__nonnull ((1));
207 /* Return 1 if SIGNO is in SET, 0 if not. */
208 extern int sigismember (const sigset_t
*__set
, int __signo
)
209 __THROW
__nonnull ((1));
212 /* Return non-empty value is SET is not empty. */
213 extern int sigisemptyset (const sigset_t
*__set
) __THROW
__nonnull ((1));
215 /* Build new signal set by combining the two inputs set using logical AND. */
216 extern int sigandset (sigset_t
*__set
, const sigset_t
*__left
,
217 const sigset_t
*__right
) __THROW
__nonnull ((1, 2, 3));
219 /* Build new signal set by combining the two inputs set using logical OR. */
220 extern int sigorset (sigset_t
*__set
, const sigset_t
*__left
,
221 const sigset_t
*__right
) __THROW
__nonnull ((1, 2, 3));
224 /* Get the system-specific definitions of `struct sigaction'
225 and the `SA_*' and `SIG_*'. constants. */
226 # include <bits/sigaction.h>
228 /* Get and/or change the set of blocked signals. */
229 extern int sigprocmask (int __how
, const sigset_t
*__restrict __set
,
230 sigset_t
*__restrict __oset
) __THROW
;
232 /* Change the set of blocked signals to SET,
233 wait until a signal arrives, and restore the set of blocked signals.
235 This function is a cancellation point and therefore not marked with
237 extern int sigsuspend (const sigset_t
*__set
) __nonnull ((1));
239 /* Get and/or set the action for signal SIG. */
240 extern int sigaction (int __sig
, const struct sigaction
*__restrict __act
,
241 struct sigaction
*__restrict __oact
) __THROW
;
243 /* Put in SET all signals that are blocked and waiting to be delivered. */
244 extern int sigpending (sigset_t
*__set
) __THROW
__nonnull ((1));
247 # ifdef __USE_POSIX199506
248 /* Select any of pending signals from SET or wait for any to arrive.
250 This function is a cancellation point and therefore not marked with
252 extern int sigwait (const sigset_t
*__restrict __set
, int *__restrict __sig
)
254 # endif /* Use POSIX 1995. */
256 # ifdef __USE_POSIX199309
257 /* Select any of pending signals from SET and place information in INFO.
259 This function is a cancellation point and therefore not marked with
261 extern int sigwaitinfo (const sigset_t
*__restrict __set
,
262 siginfo_t
*__restrict __info
) __nonnull ((1));
264 /* Select any of pending signals from SET and place information in INFO.
265 Wait the time specified by TIMEOUT if no signal is pending.
267 This function is a cancellation point and therefore not marked with
269 extern int sigtimedwait (const sigset_t
*__restrict __set
,
270 siginfo_t
*__restrict __info
,
271 const struct timespec
*__restrict __timeout
)
274 /* Send signal SIG to the process PID. Associate data in VAL with the
276 extern int sigqueue (__pid_t __pid
, int __sig
, const union sigval __val
)
278 # endif /* Use POSIX 199306. */
280 #endif /* Use POSIX. */
284 /* Names of the signals. This variable exists only for compatibility.
285 Use `strsignal' instead (see <string.h>). */
286 extern const char *const _sys_siglist
[_NSIG
];
287 extern const char *const sys_siglist
[_NSIG
];
290 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
291 # include <bits/sigcontext.h>
293 /* Restore the state saved in SCP. */
294 extern int sigreturn (struct sigcontext
*__scp
) __THROW
;
296 #endif /* Use misc. */
299 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
300 # define __need_size_t
303 # include <bits/types/stack_t.h>
304 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
305 /* This will define `ucontext_t' and `mcontext_t'. */
306 # include <sys/ucontext.h>
308 #endif /* Use POSIX.1-2008 or X/Open Unix. */
310 #if defined __USE_XOPEN_EXTENDED || defined __USE_MISC
311 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
312 (causing them to fail with EINTR); if INTERRUPT is zero, make system
313 calls be restarted after signal SIG. */
314 extern int siginterrupt (int __sig
, int __interrupt
) __THROW
;
316 # include <bits/sigstack.h>
317 # include <bits/ss_flags.h>
319 /* Alternate signal handler stack interface.
320 This interface should always be preferred over `sigstack'. */
321 extern int sigaltstack (const stack_t
*__restrict __ss
,
322 stack_t
*__restrict __oss
) __THROW
;
323 #endif /* __USE_XOPEN_EXTENDED || __USE_MISC */
325 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
326 || defined __USE_MISC)
327 # include <bits/types/struct_sigstack.h>
330 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
331 || defined __USE_MISC)
332 /* Run signals handlers on the stack specified by SS (if not NULL).
333 If OSS is not NULL, it is filled in with the old signal stack status.
334 This interface is obsolete and on many platform not implemented. */
335 extern int sigstack (struct sigstack
*__ss
, struct sigstack
*__oss
)
336 __THROW __attribute_deprecated__
;
339 #ifdef __USE_XOPEN_EXTENDED
340 /* Simplified interface for signal management. */
342 /* Add SIG to the calling process' signal mask. */
343 extern int sighold (int __sig
) __THROW
;
345 /* Remove SIG from the calling process' signal mask. */
346 extern int sigrelse (int __sig
) __THROW
;
348 /* Set the disposition of SIG to SIG_IGN. */
349 extern int sigignore (int __sig
) __THROW
;
351 /* Set the disposition of SIG. */
352 extern __sighandler_t
sigset (int __sig
, __sighandler_t __disp
) __THROW
;
355 #if defined __USE_POSIX199506 || defined __USE_UNIX98
356 /* Some of the functions for handling signals in threaded programs must
358 # include <bits/pthreadtypes.h>
359 # include <bits/sigthread.h>
360 #endif /* use Unix98 */
362 /* The following functions are used internally in the C library and in
363 other code which need deep insights. */
365 /* Return number of available real-time signal with highest priority. */
366 extern int __libc_current_sigrtmin (void) __THROW
;
367 /* Return number of available real-time signal with lowest priority. */
368 extern int __libc_current_sigrtmax (void) __THROW
;
370 #define SIGRTMIN (__libc_current_sigrtmin ())
371 #define SIGRTMAX (__libc_current_sigrtmax ())
375 #endif /* not signal.h */