Update.
[glibc.git] / signal / signal.h
blob2ae76a1f37d8dce4c198bf1f907b33fdb216d80b
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 C Standard: 4.7 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 #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;
42 # endif
43 #endif
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;
50 # endif
51 #endif
53 #ifdef _SIGNAL_H
55 #include <bits/types.h>
56 #include <bits/signum.h>
58 #ifdef __USE_XOPEN
59 # ifndef __pid_t_defined
60 typedef __pid_t pid_t;
61 # define __pid_t_defined
62 # endif
63 # ifndef __uid_t_defined
64 typedef __uid_t uid_t;
65 # define __uid_t_defined
66 # endif
67 #endif /* Unix98 */
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
75 requested. */
76 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
77 __THROW;
78 #ifdef __USE_GNU
79 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
80 __THROW;
81 #endif
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. */
86 #ifdef __USE_BSD
87 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
88 #else
89 /* Make sure the used `signal' implementation is the SVID version. */
90 # ifdef __REDIRECT
91 extern __sighandler_t __REDIRECT (signal,
92 (int __sig,
93 __sighandler_t __handler) __THROW,
94 __sysv_signal);
95 # else
96 # define signal __sysv_signal
97 # endif
98 #endif
100 #ifdef __USE_XOPEN
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;
104 #endif
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. */
109 #ifdef __USE_POSIX
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;
123 #ifdef __USE_SVID
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. */
129 #ifdef __USE_MISC
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;
142 #ifdef __USE_BSD
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)
147 #else
148 # ifdef __USE_XOPEN
149 # ifdef __GNUC__
150 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause") __THROW;
151 # endif
152 /* Remove a signal from the signal mask and suspend the process. */
153 # define sigpause(sig) __sigpause ((sig), 1)
154 # endif
155 #endif
158 #ifdef __USE_BSD
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. */
178 #ifdef __USE_MISC
179 # define NSIG _NSIG
180 #endif
182 #ifdef __USE_GNU
183 typedef __sighandler_t sighandler_t;
184 #endif
186 /* 4.4 BSD uses the name `sig_t' for this. */
187 #ifdef __USE_BSD
188 typedef __sighandler_t sig_t;
189 #endif
191 #ifdef __USE_POSIX
193 # ifdef __USE_POSIX199309
194 /* We need `struct timespec' later on. */
195 # define __need_timespec
196 # include <time.h>
198 /* Get the `siginfo_t' type plus the needed symbols. */
199 # include <bits/siginfo.h>
200 # endif
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;
217 # ifdef __USE_GNU
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;
228 # endif /* GNU */
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 *__set, sigset_t *__oset)
236 __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 *__act,
244 struct sigaction *__oact) __THROW;
245 extern int sigaction (int __sig, __const struct sigaction *__act,
246 struct sigaction *__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 *__set, int *__sig) __THROW;
255 # ifdef __USE_POSIX199309
256 /* Select any of pending signals from SET and place information in INFO. */
257 extern int sigwaitinfo (__const sigset_t *__set, siginfo_t *__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 *__set, siginfo_t *__info,
262 __const struct timespec *__timeout) __THROW;
264 /* Send signal SIG to the process PID. Associate data in VAL with the
265 signal. */
266 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
267 __THROW;
268 # endif /* Use POSIX 199306. */
270 #endif /* Use POSIX. */
272 #ifdef __USE_BSD
274 /* Names of the signals. This variable exists only for compatibility.
275 Use `strsignal' instead (see <string.h>). */
276 extern __const char *__const _sys_siglist[_NSIG];
277 extern __const char *__const sys_siglist[_NSIG];
279 /* Structure passed to `sigvec'. */
280 struct sigvec
282 __sighandler_t sv_handler; /* Signal handler. */
283 int sv_mask; /* Mask of signals to be blocked. */
285 int sv_flags; /* Flags (see below). */
286 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
289 /* Bits in `sv_flags'. */
290 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
291 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
292 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
295 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
296 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
297 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
298 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
299 it is filled in with the old information for SIG. */
300 extern int sigvec (int __sig, __const struct sigvec *__vec,
301 struct sigvec *__ovec) __THROW;
304 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
305 # include <bits/sigcontext.h>
307 /* Restore the state saved in SCP. */
308 extern int sigreturn (struct sigcontext *__scp) __THROW;
310 #endif /* use BSD. */
313 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
315 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
316 (causing them to fail with EINTR); if INTERRUPT is zero, make system
317 calls be restarted after signal SIG. */
318 extern int siginterrupt (int __sig, int __interrupt) __THROW;
320 # include <bits/sigstack.h>
321 # ifdef __USE_XOPEN
322 # include <ucontext.h>
323 # endif
325 /* Run signals handlers on the stack specified by SS (if not NULL).
326 If OSS is not NULL, it is filled in with the old signal stack status.
327 This interface is obsolete and on many platform not implemented. */
328 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
330 /* Alternate signal handler stack interface.
331 This interface should always be preferred over `sigstack'. */
332 extern int sigaltstack (__const struct sigaltstack *__ss,
333 struct sigaltstack *__oss) __THROW;
335 #endif /* use BSD or X/Open Unix. */
337 #ifdef __USE_UNIX98
338 /* Simplified interface for signal management. */
340 /* Add SIG to the calling process' signal mask. */
341 extern int sighold (int __sig) __THROW;
343 /* Remove SIG from the calling process' signal mask. */
344 extern int sigrelse (int __sig) __THROW;
346 /* Set the disposition of SIG to SIG_IGN. */
347 extern int sigignore (int __sig) __THROW;
349 /* Set the disposition of SIG. */
350 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
352 /* Some of the functions for handling signals in threaded programs must
353 be defined here. */
354 # include <bits/sigthread.h>
355 #endif /* use Unix98 */
357 /* The following functions are used internally in the C library and in
358 other code which need deep insights. */
360 /* Return number of available real-time signal with highest priority. */
361 extern int __libc_current_sigrtmin (void) __THROW;
362 /* Return number of available real-time signal with lowest priority. */
363 extern int __libc_current_sigrtmax (void) __THROW;
365 #endif /* signal.h */
367 __END_DECLS
369 #endif /* not signal.h */