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>
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>
61 #ifdef __USE_POSIX199309
62 # include <bits/types/sigevent_t.h>
63 # include <bits/sigevent-consts.h>
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
73 extern __sighandler_t
__sysv_signal (int __sig
, __sighandler_t __handler
)
76 extern __sighandler_t
sysv_signal (int __sig
, __sighandler_t __handler
)
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. */
84 extern __sighandler_t
signal (int __sig
, __sighandler_t __handler
)
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
),
93 # define signal __sysv_signal
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
)
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. */
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
;
122 /* SVID names for the same things. */
123 extern __sighandler_t
ssignal (int __sig
, __sighandler_t __handler
)
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
147 extern int sigpause (int __sig
) __asm__ ("__xpg_sigpause");
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)
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. */
181 typedef __sighandler_t sighandler_t
;
184 /* 4.4 BSD uses the name `sig_t' for this. */
186 typedef __sighandler_t sig_t
;
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));
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));
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
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
247 extern int sigwait (const sigset_t
*__restrict __set
, int *__restrict __sig
)
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
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
263 extern int sigtimedwait (const sigset_t
*__restrict __set
,
264 siginfo_t
*__restrict __info
,
265 const struct timespec
*__restrict __timeout
)
268 /* Send signal SIG to the process PID. Associate data in VAL with the
270 extern int sigqueue (__pid_t __pid
, int __sig
, const union sigval __val
)
272 # endif /* Use POSIX 199306. */
274 #endif /* Use POSIX. */
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
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>
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>
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__
;
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
;
347 #if defined __USE_POSIX199506 || defined __USE_UNIX98
348 /* Some of the functions for handling signals in threaded programs must
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
;
364 #endif /* not signal.h */