Update.
[glibc.git] / signal / signal.h
blobfffb259f52ed7bbc3a1187861a533727ca58e6e7
1 /* Copyright (C) 1991-1999, 2000, 2001, 2002 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
17 02111-1307 USA. */
20 * ISO C99 Standard: 7.14 Signal handling <signal.h>
23 #ifndef _SIGNAL_H
25 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
26 # define _SIGNAL_H
27 #endif
29 #include <features.h>
31 __BEGIN_DECLS
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 __BEGIN_NAMESPACE_STD
41 typedef __sig_atomic_t sig_atomic_t;
42 __END_NAMESPACE_STD
43 # endif
44 # undef __need_sig_atomic_t
45 #endif
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;
51 # endif
52 # undef __need_sigset_t
53 #endif
55 #ifdef _SIGNAL_H
57 #include <bits/types.h>
58 #include <bits/signum.h>
60 #ifdef __USE_XOPEN
61 # ifndef __pid_t_defined
62 typedef __pid_t pid_t;
63 # define __pid_t_defined
64 # endif
65 # ifndef __uid_t_defined
66 typedef __uid_t uid_t;
67 # define __uid_t_defined
68 # endif
69 #endif /* Unix98 */
72 /* Type of a signal handler. */
73 typedef void (*__sighandler_t) (int);
75 /* The X/Open definition of `signal' specifies the SVID semantic. Use
76 the additional function `sysv_signal' when X/Open compatibility is
77 requested. */
78 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
79 __THROW;
80 #ifdef __USE_GNU
81 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
82 __THROW;
83 #endif
85 /* Set the handler for the signal SIG to HANDLER, returning the old
86 handler, or SIG_ERR on error.
87 By default `signal' has the BSD semantic. */
88 __BEGIN_NAMESPACE_STD
89 #ifdef __USE_BSD
90 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
91 #else
92 /* Make sure the used `signal' implementation is the SVID version. */
93 # ifdef __REDIRECT
94 extern __sighandler_t __REDIRECT (signal,
95 (int __sig,
96 __sighandler_t __handler) __THROW,
97 __sysv_signal);
98 # else
99 # define signal __sysv_signal
100 # endif
101 #endif
102 __END_NAMESPACE_STD
104 #ifdef __USE_XOPEN
105 /* The X/Open definition of `signal' conflicts with the BSD version.
106 So they defined another function `bsd_signal'. */
107 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) __THROW;
108 #endif
110 /* Send signal SIG to process number PID. If PID is zero,
111 send SIG to all processes in the current process's process group.
112 If PID is < -1, send SIG to all processes in process group - PID. */
113 #ifdef __USE_POSIX
114 extern int kill (__pid_t __pid, int __sig) __THROW;
115 #endif /* Use POSIX. */
117 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
118 /* Send SIG to all processes in process group PGRP.
119 If PGRP is zero, send SIG to all processes in
120 the current process's process group. */
121 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
122 #endif /* Use BSD || X/Open Unix. */
124 __BEGIN_NAMESPACE_STD
125 /* Raise signal SIG, i.e., send SIG to yourself. */
126 extern int raise (int __sig) __THROW;
127 __END_NAMESPACE_STD
129 #ifdef __USE_SVID
130 /* SVID names for the same things. */
131 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
132 extern int gsignal (int __sig) __THROW;
133 #endif /* Use SVID. */
135 #ifdef __USE_MISC
136 /* Print a message describing the meaning of the given signal number. */
137 extern void psignal (int __sig, __const char *__s) __THROW;
138 #endif /* Use misc. */
141 /* The `sigpause' function has two different interfaces. The original
142 BSD definition defines the argument as a mask of the signal, while
143 the more modern interface in X/Open defines it as the signal
144 number. We go with the BSD version unless the user explicitly
145 selects the X/Open version. */
146 extern int __sigpause (int __sig_or_mask, int __is_sig) __THROW;
148 #ifdef __USE_BSD
149 /* Set the mask of blocked signals to MASK,
150 wait for a signal to arrive, and then restore the mask. */
151 extern int sigpause (int __mask) __THROW;
152 # define sigpause(mask) __sigpause ((mask), 0)
153 #else
154 # ifdef __USE_XOPEN
155 # ifdef __GNUC__
156 extern int sigpause (int __sig) __THROW __asm__ ("__xpg_sigpause");
157 # endif
158 /* Remove a signal from the signal mask and suspend the process. */
159 # define sigpause(sig) __sigpause ((sig), 1)
160 # endif
161 #endif
164 #ifdef __USE_BSD
165 /* None of the following functions should be used anymore. They are here
166 only for compatibility. A single word (`int') is not guaranteed to be
167 enough to hold a complete signal mask and therefore these functions
168 simply do not work in many situations. Use `sigprocmask' instead. */
170 /* Compute mask for signal SIG. */
171 # define sigmask(sig) __sigmask(sig)
173 /* Block signals in MASK, returning the old mask. */
174 extern int sigblock (int __mask) __THROW;
176 /* Set the mask of blocked signals to MASK, returning the old mask. */
177 extern int sigsetmask (int __mask) __THROW;
179 /* Return currently selected signal mask. */
180 extern int siggetmask (void) __THROW;
181 #endif /* Use BSD. */
184 #ifdef __USE_MISC
185 # define NSIG _NSIG
186 #endif
188 #ifdef __USE_GNU
189 typedef __sighandler_t sighandler_t;
190 #endif
192 /* 4.4 BSD uses the name `sig_t' for this. */
193 #ifdef __USE_BSD
194 typedef __sighandler_t sig_t;
195 #endif
197 #ifdef __USE_POSIX
199 # ifdef __USE_POSIX199309
200 /* We need `struct timespec' later on. */
201 # define __need_timespec
202 # include <time.h>
204 /* Get the `siginfo_t' type plus the needed symbols. */
205 # include <bits/siginfo.h>
206 # endif
208 /* Clear all signals from SET. */
209 extern int sigemptyset (sigset_t *__set) __THROW;
211 /* Set all signals in SET. */
212 extern int sigfillset (sigset_t *__set) __THROW;
214 /* Add SIGNO to SET. */
215 extern int sigaddset (sigset_t *__set, int __signo) __THROW;
217 /* Remove SIGNO from SET. */
218 extern int sigdelset (sigset_t *__set, int __signo) __THROW;
220 /* Return 1 if SIGNO is in SET, 0 if not. */
221 extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
223 # ifdef __USE_GNU
224 /* Return non-empty value is SET is not empty. */
225 extern int sigisemptyset (__const sigset_t *__set) __THROW;
227 /* Build new signal set by combining the two inputs set using logical AND. */
228 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
229 __const sigset_t *__right) __THROW;
231 /* Build new signal set by combining the two inputs set using logical OR. */
232 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
233 __const sigset_t *__right) __THROW;
234 # endif /* GNU */
236 /* Get the system-specific definitions of `struct sigaction'
237 and the `SA_*' and `SIG_*'. constants. */
238 # include <bits/sigaction.h>
240 /* Get and/or change the set of blocked signals. */
241 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
242 sigset_t *__restrict __oset) __THROW;
244 /* Change the set of blocked signals to SET,
245 wait until a signal arrives, and restore the set of blocked signals. */
246 extern int sigsuspend (__const sigset_t *__set) __THROW;
248 /* Get and/or set the action for signal SIG. */
249 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
250 struct sigaction *__restrict __oact) __THROW;
252 /* Put in SET all signals that are blocked and waiting to be delivered. */
253 extern int sigpending (sigset_t *__set) __THROW;
256 /* Select any of pending signals from SET or wait for any to arrive. */
257 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
258 __THROW;
260 # ifdef __USE_POSIX199309
261 /* Select any of pending signals from SET and place information in INFO. */
262 extern int sigwaitinfo (__const sigset_t *__restrict __set,
263 siginfo_t *__restrict __info) __THROW;
265 /* Select any of pending signals from SET and place information in INFO.
266 Wait the time specified by TIMEOUT if no signal is pending. */
267 extern int sigtimedwait (__const sigset_t *__restrict __set,
268 siginfo_t *__restrict __info,
269 __const struct timespec *__restrict __timeout)
270 __THROW;
272 /* Send signal SIG to the process PID. Associate data in VAL with the
273 signal. */
274 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
275 __THROW;
276 # endif /* Use POSIX 199306. */
278 #endif /* Use POSIX. */
280 #ifdef __USE_BSD
282 /* Names of the signals. This variable exists only for compatibility.
283 Use `strsignal' instead (see <string.h>). */
284 extern __const char *__const _sys_siglist[_NSIG];
285 extern __const char *__const sys_siglist[_NSIG];
287 /* Structure passed to `sigvec'. */
288 struct sigvec
290 __sighandler_t sv_handler; /* Signal handler. */
291 int sv_mask; /* Mask of signals to be blocked. */
293 int sv_flags; /* Flags (see below). */
294 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
297 /* Bits in `sv_flags'. */
298 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
299 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
300 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
303 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
304 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
305 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
306 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
307 it is filled in with the old information for SIG. */
308 extern int sigvec (int __sig, __const struct sigvec *__vec,
309 struct sigvec *__ovec) __THROW;
312 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
313 # include <bits/sigcontext.h>
315 /* Restore the state saved in SCP. */
316 extern int sigreturn (struct sigcontext *__scp) __THROW;
318 #endif /* use BSD. */
321 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
323 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
324 (causing them to fail with EINTR); if INTERRUPT is zero, make system
325 calls be restarted after signal SIG. */
326 extern int siginterrupt (int __sig, int __interrupt) __THROW;
328 # include <bits/sigstack.h>
329 # ifdef __USE_XOPEN
330 # include <ucontext.h>
331 # endif
333 /* Run signals handlers on the stack specified by SS (if not NULL).
334 If OSS is not NULL, it is filled in with the old signal stack status.
335 This interface is obsolete and on many platform not implemented. */
336 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
338 /* Alternate signal handler stack interface.
339 This interface should always be preferred over `sigstack'. */
340 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
341 struct sigaltstack *__restrict __oss) __THROW;
343 #endif /* use BSD or X/Open Unix. */
345 #ifdef __USE_UNIX98
346 /* Simplified interface for signal management. */
348 /* Add SIG to the calling process' signal mask. */
349 extern int sighold (int __sig) __THROW;
351 /* Remove SIG from the calling process' signal mask. */
352 extern int sigrelse (int __sig) __THROW;
354 /* Set the disposition of SIG to SIG_IGN. */
355 extern int sigignore (int __sig) __THROW;
357 /* Set the disposition of SIG. */
358 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
359 #endif
361 #if defined __USE_POSIX199506 || defined __USE_UNIX98
362 /* Some of the functions for handling signals in threaded programs must
363 be defined here. */
364 # include <bits/sigthread.h>
365 #endif /* use Unix98 */
367 /* The following functions are used internally in the C library and in
368 other code which need deep insights. */
370 /* Return number of available real-time signal with highest priority. */
371 extern int __libc_current_sigrtmin (void) __THROW;
372 /* Return number of available real-time signal with lowest priority. */
373 extern int __libc_current_sigrtmax (void) __THROW;
375 #endif /* signal.h */
377 __END_DECLS
379 #endif /* not signal.h */