1 /* Copyright (C) 1991-2003, 2004 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * ISO C99 Standard: 7.14 Signal handling <signal.h>
25 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
33 #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
35 /* An integral type that can be modified atomically, without the
36 possibility of a signal arriving in the middle of the operation. */
37 #if defined __need_sig_atomic_t || defined _SIGNAL_H
38 # ifndef __sig_atomic_t_defined
39 # define __sig_atomic_t_defined
41 typedef __sig_atomic_t sig_atomic_t;
44 # undef __need_sig_atomic_t
47 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
48 # ifndef __sigset_t_defined
49 # define __sigset_t_defined
50 typedef __sigset_t sigset_t;
52 # undef __need_sigset_t
57 #include <bits/types.h>
58 #include <bits/signum.h>
60 #if defined __USE_XOPEN || defined __USE_XOPEN2K
61 # ifndef __pid_t_defined
62 typedef __pid_t pid_t;
63 # define __pid_t_defined
67 # ifndef __uid_t_defined
68 typedef __uid_t uid_t;
69 # define __uid_t_defined
74 /* Type of a signal handler. */
75 typedef void (*__sighandler_t) (int);
77 /* The X/Open definition of `signal' specifies the SVID semantic. Use
78 the additional function `sysv_signal' when X/Open compatibility is
80 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
83 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
87 /* Set the handler for the signal SIG to HANDLER, returning the old
88 handler, or SIG_ERR on error.
89 By default `signal' has the BSD semantic. */
92 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
94 /* Make sure the used `signal' implementation is the SVID version. */
95 # ifdef __REDIRECT_NTH
96 extern __sighandler_t __REDIRECT_NTH (signal,
97 (int __sig, __sighandler_t __handler),
100 # define signal __sysv_signal
106 /* The X/Open definition of `signal' conflicts with the BSD version.
107 So they defined another function `bsd_signal'. */
108 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) __THROW;
111 /* Send signal SIG to process number PID. If PID is zero,
112 send SIG to all processes in the current process's process group.
113 If PID is < -1, send SIG to all processes in process group - PID. */
115 extern int kill (__pid_t __pid, int __sig) __THROW;
116 #endif /* Use POSIX. */
118 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
119 /* Send SIG to all processes in process group PGRP.
120 If PGRP is zero, send SIG to all processes in
121 the current process's process group. */
122 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
123 #endif /* Use BSD || X/Open Unix. */
125 __BEGIN_NAMESPACE_STD
126 /* Raise signal SIG, i.e., send SIG to yourself. */
127 extern int raise (int __sig) __THROW;
131 /* SVID names for the same things. */
132 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
133 extern int gsignal (int __sig) __THROW;
134 #endif /* Use SVID. */
137 /* Print a message describing the meaning of the given signal number. */
138 extern void psignal (int __sig, __const char *__s);
139 #endif /* Use misc. */
142 /* The `sigpause' function has two different interfaces. The original
143 BSD definition defines the argument as a mask of the signal, while
144 the more modern interface in X/Open defines it as the signal
145 number. We go with the BSD version unless the user explicitly
146 selects the X/Open version.
148 This function is a cancellation point and therefore not marked with
150 extern int __sigpause (int __sig_or_mask, int __is_sig);
153 /* Set the mask of blocked signals to MASK,
154 wait for a signal to arrive, and then restore the mask. */
155 extern int sigpause (int __mask) __THROW __attribute_deprecated__;
159 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
161 /* Remove a signal from the signal mask and suspend the process. */
162 # define sigpause(sig) __sigpause ((sig), 1)
169 /* None of the following functions should be used anymore. They are here
170 only for compatibility. A single word (`int') is not guaranteed to be
171 enough to hold a complete signal mask and therefore these functions
172 simply do not work in many situations. Use `sigprocmask' instead. */
174 /* Compute mask for signal SIG. */
175 # define sigmask(sig) __sigmask(sig)
177 /* Block signals in MASK, returning the old mask. */
178 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
180 /* Set the mask of blocked signals to MASK, returning the old mask. */
181 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
183 /* Return currently selected signal mask. */
184 extern int siggetmask (void) __THROW __attribute_deprecated__;
185 #endif /* Use BSD. */
193 typedef __sighandler_t sighandler_t;
196 /* 4.4 BSD uses the name `sig_t' for this. */
198 typedef __sighandler_t sig_t;
203 # ifdef __USE_POSIX199309
204 /* We need `struct timespec' later on. */
205 # define __need_timespec
208 /* Get the `siginfo_t' type plus the needed symbols. */
209 # include <bits/siginfo.h>
212 /* Clear all signals from SET. */
213 extern int sigemptyset (sigset_t *__set) __THROW;
215 /* Set all signals in SET. */
216 extern int sigfillset (sigset_t *__set) __THROW;
218 /* Add SIGNO to SET. */
219 extern int sigaddset (sigset_t *__set, int __signo) __THROW;
221 /* Remove SIGNO from SET. */
222 extern int sigdelset (sigset_t *__set, int __signo) __THROW;
224 /* Return 1 if SIGNO is in SET, 0 if not. */
225 extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
228 /* Return non-empty value is SET is not empty. */
229 extern int sigisemptyset (__const sigset_t *__set) __THROW;
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;
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;
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
253 extern int sigsuspend (__const sigset_t *__set);
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;
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
267 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig);
269 # ifdef __USE_POSIX199309
270 /* Select any of pending signals from SET and place information in INFO.
272 This function is a cancellation point and therefore not marked with
274 extern int sigwaitinfo (__const sigset_t *__restrict __set,
275 siginfo_t *__restrict __info);
277 /* Select any of pending signals from SET and place information in INFO.
278 Wait the time specified by TIMEOUT if no signal is pending.
280 This function is a cancellation point and therefore not marked with
282 extern int sigtimedwait (__const sigset_t *__restrict __set,
283 siginfo_t *__restrict __info,
284 __const struct timespec *__restrict __timeout);
286 /* Send signal SIG to the process PID. Associate data in VAL with the
288 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
290 # endif /* Use POSIX 199306. */
292 #endif /* Use POSIX. */
296 /* Names of the signals. This variable exists only for compatibility.
297 Use `strsignal' instead (see <string.h>). */
298 extern __const char *__const _sys_siglist[_NSIG];
299 extern __const char *__const sys_siglist[_NSIG];
301 /* Structure passed to `sigvec'. */
304 __sighandler_t sv_handler; /* Signal handler. */
305 int sv_mask; /* Mask of signals to be blocked. */
307 int sv_flags; /* Flags (see below). */
308 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
311 /* Bits in `sv_flags'. */
312 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
313 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
314 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
317 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
318 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
319 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
320 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
321 it is filled in with the old information for SIG. */
322 extern int sigvec (int __sig, __const struct sigvec *__vec,
323 struct sigvec *__ovec) __THROW;
326 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
327 # include <bits/sigcontext.h>
329 /* Restore the state saved in SCP. */
330 extern int sigreturn (struct sigcontext *__scp) __THROW;
332 #endif /* use BSD. */
335 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
337 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
338 (causing them to fail with EINTR); if INTERRUPT is zero, make system
339 calls be restarted after signal SIG. */
340 extern int siginterrupt (int __sig, int __interrupt) __THROW;
342 # include <bits/sigstack.h>
344 /* This will define `ucontext_t' and `mcontext_t'. */
345 # include <sys/ucontext.h>
348 /* Run signals handlers on the stack specified by SS (if not NULL).
349 If OSS is not NULL, it is filled in with the old signal stack status.
350 This interface is obsolete and on many platform not implemented. */
351 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
352 __THROW __attribute_deprecated__;
354 /* Alternate signal handler stack interface.
355 This interface should always be preferred over `sigstack'. */
356 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
357 struct sigaltstack *__restrict __oss) __THROW;
359 #endif /* use BSD or X/Open Unix. */
361 #ifdef __USE_XOPEN_EXTENDED
362 /* Simplified interface for signal management. */
364 /* Add SIG to the calling process' signal mask. */
365 extern int sighold (int __sig) __THROW;
367 /* Remove SIG from the calling process' signal mask. */
368 extern int sigrelse (int __sig) __THROW;
370 /* Set the disposition of SIG to SIG_IGN. */
371 extern int sigignore (int __sig) __THROW;
373 /* Set the disposition of SIG. */
374 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
377 #if defined __USE_POSIX199506 || defined __USE_UNIX98
378 /* Some of the functions for handling signals in threaded programs must
380 # include <bits/pthreadtypes.h>
381 # include <bits/sigthread.h>
382 #endif /* use Unix98 */
384 /* The following functions are used internally in the C library and in
385 other code which need deep insights. */
387 /* Return number of available real-time signal with highest priority. */
388 extern int __libc_current_sigrtmin (void) __THROW;
389 /* Return number of available real-time signal with lowest priority. */
390 extern int __libc_current_sigrtmax (void) __THROW;
392 #endif /* signal.h */
396 #endif /* not signal.h */