1 /* Copyright (C) 1991-1999, 2000, 2001 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
40 typedef __sig_atomic_t sig_atomic_t;
42 # undef __need_sig_atomic_t
45 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
46 # ifndef __sigset_t_defined
47 # define __sigset_t_defined
48 typedef __sigset_t sigset_t;
50 # undef __need_sigset_t
55 #include <bits/types.h>
56 #include <bits/signum.h>
59 # ifndef __pid_t_defined
60 typedef __pid_t pid_t;
61 # define __pid_t_defined
63 # ifndef __uid_t_defined
64 typedef __uid_t uid_t;
65 # define __uid_t_defined
70 /* Type of a signal handler. */
71 typedef void (*__sighandler_t) (int);
73 /* The X/Open definition of `signal' specifies the SVID semantic. Use
74 the additional function `sysv_signal' when X/Open compatibility is
76 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
79 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
83 /* Set the handler for the signal SIG to HANDLER, returning the old
84 handler, or SIG_ERR on error.
85 By default `signal' has the BSD semantic. */
87 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
89 /* Make sure the used `signal' implementation is the SVID version. */
91 extern __sighandler_t __REDIRECT (signal,
93 __sighandler_t __handler) __THROW,
96 # define signal __sysv_signal
101 /* The X/Open definition of `signal' conflicts with the BSD version.
102 So they defined another function `bsd_signal'. */
103 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) __THROW;
106 /* Send signal SIG to process number PID. If PID is zero,
107 send SIG to all processes in the current process's process group.
108 If PID is < -1, send SIG to all processes in process group - PID. */
110 extern int kill (__pid_t __pid, int __sig) __THROW;
111 #endif /* Use POSIX. */
113 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
114 /* Send SIG to all processes in process group PGRP.
115 If PGRP is zero, send SIG to all processes in
116 the current process's process group. */
117 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
118 #endif /* Use BSD || X/Open Unix. */
120 /* Raise signal SIG, i.e., send SIG to yourself. */
121 extern int raise (int __sig) __THROW;
124 /* SVID names for the same things. */
125 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
126 extern int gsignal (int __sig) __THROW;
127 #endif /* Use SVID. */
130 /* Print a message describing the meaning of the given signal number. */
131 extern void psignal (int __sig, __const char *__s) __THROW;
132 #endif /* Use misc. */
135 /* The `sigpause' function has two different interfaces. The original
136 BSD definition defines the argument as a mask of the signal, while
137 the more modern interface in X/Open defines it as the signal
138 number. We go with the BSD version unless the user explicitly
139 selects the X/Open version. */
140 extern int __sigpause (int __sig_or_mask, int __is_sig) __THROW;
143 /* Set the mask of blocked signals to MASK,
144 wait for a signal to arrive, and then restore the mask. */
145 extern int sigpause (int __mask) __THROW;
146 # define sigpause(mask) __sigpause ((mask), 0)
150 extern int sigpause (int __sig) __THROW __asm__ ("__xpg_sigpause");
152 /* Remove a signal from the signal mask and suspend the process. */
153 # define sigpause(sig) __sigpause ((sig), 1)
159 /* None of the following functions should be used anymore. They are here
160 only for compatibility. A single word (`int') is not guaranteed to be
161 enough to hold a complete signal mask and therefore these functions
162 simply do not work in many situations. Use `sigprocmask' instead. */
164 /* Compute mask for signal SIG. */
165 # define sigmask(sig) __sigmask(sig)
167 /* Block signals in MASK, returning the old mask. */
168 extern int sigblock (int __mask) __THROW;
170 /* Set the mask of blocked signals to MASK, returning the old mask. */
171 extern int sigsetmask (int __mask) __THROW;
173 /* Return currently selected signal mask. */
174 extern int siggetmask (void) __THROW;
175 #endif /* Use BSD. */
183 typedef __sighandler_t sighandler_t;
186 /* 4.4 BSD uses the name `sig_t' for this. */
188 typedef __sighandler_t sig_t;
193 # ifdef __USE_POSIX199309
194 /* We need `struct timespec' later on. */
195 # define __need_timespec
198 /* Get the `siginfo_t' type plus the needed symbols. */
199 # include <bits/siginfo.h>
202 /* Clear all signals from SET. */
203 extern int sigemptyset (sigset_t *__set) __THROW;
205 /* Set all signals in SET. */
206 extern int sigfillset (sigset_t *__set) __THROW;
208 /* Add SIGNO to SET. */
209 extern int sigaddset (sigset_t *__set, int __signo) __THROW;
211 /* Remove SIGNO from SET. */
212 extern int sigdelset (sigset_t *__set, int __signo) __THROW;
214 /* Return 1 if SIGNO is in SET, 0 if not. */
215 extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
218 /* Return non-empty value is SET is not empty. */
219 extern int sigisemptyset (__const sigset_t *__set) __THROW;
221 /* Build new signal set by combining the two inputs set using logical AND. */
222 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
223 __const sigset_t *__right) __THROW;
225 /* Build new signal set by combining the two inputs set using logical OR. */
226 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
227 __const sigset_t *__right) __THROW;
230 /* Get the system-specific definitions of `struct sigaction'
231 and the `SA_*' and `SIG_*'. constants. */
232 # include <bits/sigaction.h>
234 /* Get and/or change the set of blocked signals. */
235 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
236 sigset_t *__restrict __oset) __THROW;
238 /* Change the set of blocked signals to SET,
239 wait until a signal arrives, and restore the set of blocked signals. */
240 extern int sigsuspend (__const sigset_t *__set) __THROW;
242 /* Get and/or set the action for signal SIG. */
243 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
244 struct sigaction *__restrict __oact) __THROW;
246 /* Put in SET all signals that are blocked and waiting to be delivered. */
247 extern int sigpending (sigset_t *__set) __THROW;
250 /* Select any of pending signals from SET or wait for any to arrive. */
251 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
254 # ifdef __USE_POSIX199309
255 /* Select any of pending signals from SET and place information in INFO. */
256 extern int sigwaitinfo (__const sigset_t *__restrict __set,
257 siginfo_t *__restrict __info) __THROW;
259 /* Select any of pending signals from SET and place information in INFO.
260 Wait the imte specified by TIMEOUT if no signal is pending. */
261 extern int sigtimedwait (__const sigset_t *__restrict __set,
262 siginfo_t *__restrict __info,
263 __const struct timespec *__restrict __timeout)
266 /* Send signal SIG to the process PID. Associate data in VAL with the
268 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
270 # endif /* Use POSIX 199306. */
272 #endif /* Use POSIX. */
276 /* Names of the signals. This variable exists only for compatibility.
277 Use `strsignal' instead (see <string.h>). */
278 extern __const char *__const _sys_siglist[_NSIG];
279 extern __const char *__const sys_siglist[_NSIG];
281 /* Structure passed to `sigvec'. */
284 __sighandler_t sv_handler; /* Signal handler. */
285 int sv_mask; /* Mask of signals to be blocked. */
287 int sv_flags; /* Flags (see below). */
288 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
291 /* Bits in `sv_flags'. */
292 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
293 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
294 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
297 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
298 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
299 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
300 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
301 it is filled in with the old information for SIG. */
302 extern int sigvec (int __sig, __const struct sigvec *__vec,
303 struct sigvec *__ovec) __THROW;
306 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
307 # include <bits/sigcontext.h>
309 /* Restore the state saved in SCP. */
310 extern int sigreturn (struct sigcontext *__scp) __THROW;
312 #endif /* use BSD. */
315 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
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>
324 # include <ucontext.h>
327 /* Run signals handlers on the stack specified by SS (if not NULL).
328 If OSS is not NULL, it is filled in with the old signal stack status.
329 This interface is obsolete and on many platform not implemented. */
330 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
332 /* Alternate signal handler stack interface.
333 This interface should always be preferred over `sigstack'. */
334 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
335 struct sigaltstack *__restrict __oss) __THROW;
337 #endif /* use BSD or X/Open Unix. */
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 _POSIX_THREADS && (defined __USE_POSIX199506 || defined __USE_UNIX98)
356 /* Some of the functions for handling signals in threaded programs must
358 # include <bits/sigthread.h>
359 #endif /* use Unix98 */
361 /* The following functions are used internally in the C library and in
362 other code which need deep insights. */
364 /* Return number of available real-time signal with highest priority. */
365 extern int __libc_current_sigrtmin (void) __THROW;
366 /* Return number of available real-time signal with lowest priority. */
367 extern int __libc_current_sigrtmax (void) __THROW;
369 #endif /* signal.h */
373 #endif /* not signal.h */