1 /* Copyright (C) 1991-1999, 2000 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
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 #ifndef __sig_atomic_t_defined
38 # if defined __need_sig_atomic_t || defined _SIGNAL_H
39 # undef __need_sig_atomic_t
40 # define __sig_atomic_t_defined
41 typedef __sig_atomic_t sig_atomic_t;
45 #ifndef __sigset_t_defined
46 # if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
47 # undef __need_sigset_t
48 # define __sigset_t_defined
49 typedef __sigset_t 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;
245 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
246 struct sigaction *__restrict __oact) __THROW;
248 /* Put in SET all signals that are blocked and waiting to be delivered. */
249 extern int sigpending (sigset_t *__set) __THROW;
252 /* Select any of pending signals from SET or wait for any to arrive. */
253 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
256 # ifdef __USE_POSIX199309
257 /* Select any of pending signals from SET and place information in INFO. */
258 extern int sigwaitinfo (__const sigset_t *__restrict __set,
259 siginfo_t *__restrict __info) __THROW;
261 /* Select any of pending signals from SET and place information in INFO.
262 Wait the imte specified by TIMEOUT if no signal is pending. */
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];
283 /* Structure passed to `sigvec'. */
286 __sighandler_t sv_handler; /* Signal handler. */
287 int sv_mask; /* Mask of signals to be blocked. */
289 int sv_flags; /* Flags (see below). */
290 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
293 /* Bits in `sv_flags'. */
294 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
295 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
296 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
299 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
300 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
301 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
302 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
303 it is filled in with the old information for SIG. */
304 extern int sigvec (int __sig, __const struct sigvec *__vec,
305 struct sigvec *__ovec) __THROW;
308 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
309 # include <bits/sigcontext.h>
311 /* Restore the state saved in SCP. */
312 extern int sigreturn (struct sigcontext *__scp) __THROW;
314 #endif /* use BSD. */
317 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
319 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
320 (causing them to fail with EINTR); if INTERRUPT is zero, make system
321 calls be restarted after signal SIG. */
322 extern int siginterrupt (int __sig, int __interrupt) __THROW;
324 # include <bits/sigstack.h>
326 # include <ucontext.h>
329 /* Run signals handlers on the stack specified by SS (if not NULL).
330 If OSS is not NULL, it is filled in with the old signal stack status.
331 This interface is obsolete and on many platform not implemented. */
332 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
334 /* Alternate signal handler stack interface.
335 This interface should always be preferred over `sigstack'. */
336 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
337 struct sigaltstack *__restrict __oss) __THROW;
339 #endif /* use BSD or X/Open Unix. */
342 /* Simplified interface for signal management. */
344 /* Add SIG to the calling process' signal mask. */
345 extern int sighold (int __sig) __THROW;
347 /* Remove SIG from the calling process' signal mask. */
348 extern int sigrelse (int __sig) __THROW;
350 /* Set the disposition of SIG to SIG_IGN. */
351 extern int sigignore (int __sig) __THROW;
353 /* Set the disposition of SIG. */
354 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
357 #if defined __USE_POSIX199506 || defined __USE_UNIX98
358 /* Some of the functions for handling signals in threaded programs must
360 # include <bits/sigthread.h>
361 #endif /* use Unix98 */
363 /* The following functions are used internally in the C library and in
364 other code which need deep insights. */
366 /* Return number of available real-time signal with highest priority. */
367 extern int __libc_current_sigrtmin (void) __THROW;
368 /* Return number of available real-time signal with lowest priority. */
369 extern int __libc_current_sigrtmax (void) __THROW;
371 #endif /* signal.h */
375 #endif /* not signal.h */