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>
24 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
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 typedef __sig_atomic_t
sig_atomic_t;
41 # undef __need_sig_atomic_t
44 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
45 # ifndef __sigset_t_defined
46 # define __sigset_t_defined
47 typedef __sigset_t sigset_t
;
49 # undef __need_sigset_t
54 #include <bits/types.h>
55 #include <bits/signum.h>
57 #if defined __USE_XOPEN || defined __USE_XOPEN2K
58 # ifndef __pid_t_defined
59 typedef __pid_t pid_t
;
60 # define __pid_t_defined
64 # ifndef __uid_t_defined
65 typedef __uid_t uid_t
;
66 # define __uid_t_defined
70 #ifdef __USE_POSIX199309
71 /* We need `struct timespec' later on. */
72 # include <bits/types/struct_timespec.h>
75 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
76 /* Get the `siginfo_t' type plus the needed symbols. */
77 # include <bits/siginfo.h>
81 /* Type of a signal handler. */
82 typedef void (*__sighandler_t
) (int);
84 /* The X/Open definition of `signal' specifies the SVID semantic. Use
85 the additional function `sysv_signal' when X/Open compatibility is
87 extern __sighandler_t
__sysv_signal (int __sig
, __sighandler_t __handler
)
90 extern __sighandler_t
sysv_signal (int __sig
, __sighandler_t __handler
)
94 /* Set the handler for the signal SIG to HANDLER, returning the old
95 handler, or SIG_ERR on error.
96 By default `signal' has the BSD semantic. */
98 extern __sighandler_t
signal (int __sig
, __sighandler_t __handler
)
101 /* Make sure the used `signal' implementation is the SVID version. */
102 # ifdef __REDIRECT_NTH
103 extern __sighandler_t
__REDIRECT_NTH (signal
,
104 (int __sig
, __sighandler_t __handler
),
107 # define signal __sysv_signal
111 #if defined __USE_XOPEN && !defined __USE_XOPEN2K8
112 /* The X/Open definition of `signal' conflicts with the BSD version.
113 So they defined another function `bsd_signal'. */
114 extern __sighandler_t
bsd_signal (int __sig
, __sighandler_t __handler
)
118 /* Send signal SIG to process number PID. If PID is zero,
119 send SIG to all processes in the current process's process group.
120 If PID is < -1, send SIG to all processes in process group - PID. */
122 extern int kill (__pid_t __pid
, int __sig
) __THROW
;
123 #endif /* Use POSIX. */
125 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
126 /* Send SIG to all processes in process group PGRP.
127 If PGRP is zero, send SIG to all processes in
128 the current process's process group. */
129 extern int killpg (__pid_t __pgrp
, int __sig
) __THROW
;
130 #endif /* Use misc || X/Open Unix. */
132 /* Raise signal SIG, i.e., send SIG to yourself. */
133 extern int raise (int __sig
) __THROW
;
136 /* SVID names for the same things. */
137 extern __sighandler_t
ssignal (int __sig
, __sighandler_t __handler
)
139 extern int gsignal (int __sig
) __THROW
;
140 #endif /* Use misc. */
142 #ifdef __USE_XOPEN2K8
143 /* Print a message describing the meaning of the given signal number. */
144 extern void psignal (int __sig
, const char *__s
);
146 /* Print a message describing the meaning of the given signal information. */
147 extern void psiginfo (const siginfo_t
*__pinfo
, const char *__s
);
148 #endif /* POSIX 2008. */
152 /* The `sigpause' function in X/Open defines the argument as the
153 signal number. This requires redirecting to another function
154 because the default version in glibc uses an old BSD interface.
156 This function is a cancellation point and therefore not marked with
161 extern int sigpause (int __sig
) __asm__ ("__xpg_sigpause");
163 extern int __sigpause (int __sig_or_mask
, int __is_sig
);
164 /* Remove a signal from the signal mask and suspend the process. */
165 # define sigpause(sig) __sigpause ((sig), 1)
171 /* None of the following functions should be used anymore. They are here
172 only for compatibility. A single word (`int') is not guaranteed to be
173 enough to hold a complete signal mask and therefore these functions
174 simply do not work in many situations. Use `sigprocmask' instead. */
176 /* Compute mask for signal SIG. */
177 # define sigmask(sig) __sigmask(sig)
179 /* Block signals in MASK, returning the old mask. */
180 extern int sigblock (int __mask
) __THROW __attribute_deprecated__
;
182 /* Set the mask of blocked signals to MASK, returning the old mask. */
183 extern int sigsetmask (int __mask
) __THROW __attribute_deprecated__
;
185 /* Return currently selected signal mask. */
186 extern int siggetmask (void) __THROW __attribute_deprecated__
;
187 #endif /* Use misc. */
195 typedef __sighandler_t sighandler_t
;
198 /* 4.4 BSD uses the name `sig_t' for this. */
200 typedef __sighandler_t sig_t
;
205 /* Clear all signals from SET. */
206 extern int sigemptyset (sigset_t
*__set
) __THROW
__nonnull ((1));
208 /* Set all signals in SET. */
209 extern int sigfillset (sigset_t
*__set
) __THROW
__nonnull ((1));
211 /* Add SIGNO to SET. */
212 extern int sigaddset (sigset_t
*__set
, int __signo
) __THROW
__nonnull ((1));
214 /* Remove SIGNO from SET. */
215 extern int sigdelset (sigset_t
*__set
, int __signo
) __THROW
__nonnull ((1));
217 /* Return 1 if SIGNO is in SET, 0 if not. */
218 extern int sigismember (const sigset_t
*__set
, int __signo
)
219 __THROW
__nonnull ((1));
222 /* Return non-empty value is SET is not empty. */
223 extern int sigisemptyset (const sigset_t
*__set
) __THROW
__nonnull ((1));
225 /* Build new signal set by combining the two inputs set using logical AND. */
226 extern int sigandset (sigset_t
*__set
, const sigset_t
*__left
,
227 const sigset_t
*__right
) __THROW
__nonnull ((1, 2, 3));
229 /* Build new signal set by combining the two inputs set using logical OR. */
230 extern int sigorset (sigset_t
*__set
, const sigset_t
*__left
,
231 const sigset_t
*__right
) __THROW
__nonnull ((1, 2, 3));
234 /* Get the system-specific definitions of `struct sigaction'
235 and the `SA_*' and `SIG_*'. constants. */
236 # include <bits/sigaction.h>
238 /* Get and/or change the set of blocked signals. */
239 extern int sigprocmask (int __how
, const sigset_t
*__restrict __set
,
240 sigset_t
*__restrict __oset
) __THROW
;
242 /* Change the set of blocked signals to SET,
243 wait until a signal arrives, and restore the set of blocked signals.
245 This function is a cancellation point and therefore not marked with
247 extern int sigsuspend (const sigset_t
*__set
) __nonnull ((1));
249 /* Get and/or set the action for signal SIG. */
250 extern int sigaction (int __sig
, const struct sigaction
*__restrict __act
,
251 struct sigaction
*__restrict __oact
) __THROW
;
253 /* Put in SET all signals that are blocked and waiting to be delivered. */
254 extern int sigpending (sigset_t
*__set
) __THROW
__nonnull ((1));
257 /* Select any of pending signals from SET or wait for any to arrive.
259 This function is a cancellation point and therefore not marked with
261 extern int sigwait (const sigset_t
*__restrict __set
, int *__restrict __sig
)
264 # ifdef __USE_POSIX199309
265 /* Select any of pending signals from SET and place information in INFO.
267 This function is a cancellation point and therefore not marked with
269 extern int sigwaitinfo (const sigset_t
*__restrict __set
,
270 siginfo_t
*__restrict __info
) __nonnull ((1));
272 /* Select any of pending signals from SET and place information in INFO.
273 Wait the time specified by TIMEOUT if no signal is pending.
275 This function is a cancellation point and therefore not marked with
277 extern int sigtimedwait (const sigset_t
*__restrict __set
,
278 siginfo_t
*__restrict __info
,
279 const struct timespec
*__restrict __timeout
)
282 /* Send signal SIG to the process PID. Associate data in VAL with the
284 extern int sigqueue (__pid_t __pid
, int __sig
, const union sigval __val
)
286 # endif /* Use POSIX 199306. */
288 #endif /* Use POSIX. */
292 /* Names of the signals. This variable exists only for compatibility.
293 Use `strsignal' instead (see <string.h>). */
294 extern const char *const _sys_siglist
[_NSIG
];
295 extern const char *const sys_siglist
[_NSIG
];
298 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
299 # include <bits/sigcontext.h>
301 /* Restore the state saved in SCP. */
302 extern int sigreturn (struct sigcontext
*__scp
) __THROW
;
304 #endif /* Use misc. */
307 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
308 # define __need_size_t
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 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
318 /* This will define `ucontext_t' and `mcontext_t'. */
319 # include <sys/ucontext.h>
322 /* Run signals handlers on the stack specified by SS (if not NULL).
323 If OSS is not NULL, it is filled in with the old signal stack status.
324 This interface is obsolete and on many platform not implemented. */
325 extern int sigstack (struct sigstack
*__ss
, struct sigstack
*__oss
)
326 __THROW __attribute_deprecated__
;
328 /* Alternate signal handler stack interface.
329 This interface should always be preferred over `sigstack'. */
330 extern int sigaltstack (const struct sigaltstack
*__restrict __ss
,
331 struct sigaltstack
*__restrict __oss
) __THROW
;
333 #endif /* Use POSIX.1-2008 or X/Open Unix. */
335 #ifdef __USE_XOPEN_EXTENDED
336 /* Simplified interface for signal management. */
338 /* Add SIG to the calling process' signal mask. */
339 extern int sighold (int __sig
) __THROW
;
341 /* Remove SIG from the calling process' signal mask. */
342 extern int sigrelse (int __sig
) __THROW
;
344 /* Set the disposition of SIG to SIG_IGN. */
345 extern int sigignore (int __sig
) __THROW
;
347 /* Set the disposition of SIG. */
348 extern __sighandler_t
sigset (int __sig
, __sighandler_t __disp
) __THROW
;
351 #if defined __USE_POSIX199506 || defined __USE_UNIX98
352 /* Some of the functions for handling signals in threaded programs must
354 # include <bits/pthreadtypes.h>
355 # include <bits/sigthread.h>
356 #endif /* use Unix98 */
358 /* The following functions are used internally in the C library and in
359 other code which need deep insights. */
361 /* Return number of available real-time signal with highest priority. */
362 extern int __libc_current_sigrtmin (void) __THROW
;
363 /* Return number of available real-time signal with lowest priority. */
364 extern int __libc_current_sigrtmax (void) __THROW
;
366 #endif /* signal.h */
370 #endif /* not signal.h */