Update.
[glibc.git] / signal / signal.h
blob12019f06f67a9e90a39e3745e7c09f42c305a6e7
1 /* Copyright (C) 1991,92,93,94,95,96,97,98,99 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 #if defined __USE_XOPEN && !defined __pid_t_defined
59 typedef __pid_t pid_t;
60 # define __pid_t_defined
61 #endif /* Unix98 */
64 /* Type of a signal handler. */
65 typedef void (*__sighandler_t) (int);
67 /* The X/Open definition of `signal' specifies the SVID semantic. Use
68 the additional function `sysv_signal' when X/Open compatibility is
69 requested. */
70 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
71 __THROW;
72 #ifdef __USE_GNU
73 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
74 __THROW;
75 #endif
77 /* Set the handler for the signal SIG to HANDLER, returning the old
78 handler, or SIG_ERR on error.
79 By default `signal' has the BSD semantic. */
80 #ifdef __USE_BSD
81 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
82 #else
83 /* Make sure the used `signal' implementation is the SVID version. */
84 # ifdef __REDIRECT
85 extern __sighandler_t __REDIRECT (signal,
86 (int __sig,
87 __sighandler_t __handler) __THROW,
88 __sysv_signal);
89 # else
90 # define signal __sysv_signal
91 # endif
92 #endif
94 #ifdef __USE_XOPEN
95 /* The X/Open definition of `signal' conflicts with the BSD version.
96 So they defined another function `bsd_signal'. */
97 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) __THROW;
98 #endif
100 /* Send signal SIG to process number PID. If PID is zero,
101 send SIG to all processes in the current process's process group.
102 If PID is < -1, send SIG to all processes in process group - PID. */
103 #ifdef __USE_POSIX
104 extern int kill (__pid_t __pid, int __sig) __THROW;
105 #endif /* Use POSIX. */
107 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
108 /* Send SIG to all processes in process group PGRP.
109 If PGRP is zero, send SIG to all processes in
110 the current process's process group. */
111 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
112 #endif /* Use BSD || X/Open Unix. */
114 /* Raise signal SIG, i.e., send SIG to yourself. */
115 extern int raise (int __sig) __THROW;
117 #ifdef __USE_SVID
118 /* SVID names for the same things. */
119 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
120 extern int gsignal (int __sig) __THROW;
121 #endif /* Use SVID. */
123 #ifdef __USE_MISC
124 /* Print a message describing the meaning of the given signal number. */
125 extern void psignal (int __sig, __const char *__s) __THROW;
126 #endif /* Use misc. */
129 /* The `sigpause' function has two different interfaces. The original
130 BSD definition defines the argument as a mask of the signal, while
131 the more modern interface in X/Open defines it as the signal
132 number. We go with the BSD version unless the user explicitly
133 selects the X/Open version. */
134 extern int __sigpause (int __sig_or_mask, int __is_sig) __THROW;
136 #ifdef __USE_BSD
137 /* Set the mask of blocked signals to MASK,
138 wait for a signal to arrive, and then restore the mask. */
139 extern int sigpause (int __mask) __THROW;
140 # define sigpause(mask) __sigpause ((mask), 0)
141 #else
142 # ifdef __USE_XOPEN
143 /* Remove a signal from the signal mask and suspend the process. */
144 # define sigpause(sig) __sigpause ((sig), 1)
145 # endif
146 #endif
149 #ifdef __USE_BSD
150 /* None of the following functions should be used anymore. They are here
151 only for compatibility. A single word (`int') is not guaranteed to be
152 enough to hold a complete signal mask and therefore these functions
153 simply do not work in many situations. Use `sigprocmask' instead. */
155 /* Compute mask for signal SIG. */
156 # define sigmask(sig) __sigmask(sig)
158 /* Block signals in MASK, returning the old mask. */
159 extern int sigblock (int __mask) __THROW;
161 /* Set the mask of blocked signals to MASK, returning the old mask. */
162 extern int sigsetmask (int __mask) __THROW;
164 /* Return currently selected signal mask. */
165 extern int siggetmask (void) __THROW;
166 #endif /* Use BSD. */
169 #ifdef __USE_MISC
170 # define NSIG _NSIG
171 #endif
173 #ifdef __USE_GNU
174 typedef __sighandler_t sighandler_t;
175 #endif
177 /* 4.4 BSD uses the name `sig_t' for this. */
178 #ifdef __USE_BSD
179 typedef __sighandler_t sig_t;
180 #endif
182 #ifdef __USE_POSIX
184 # ifdef __USE_POSIX199309
185 /* We need `struct timespec' later on. */
186 # define __need_timespec
187 # include <time.h>
189 /* Get the `siginfo_t' type plus the needed symbols. */
190 # include <bits/siginfo.h>
191 # endif
193 /* Clear all signals from SET. */
194 extern int sigemptyset (sigset_t *__set) __THROW;
196 /* Set all signals in SET. */
197 extern int sigfillset (sigset_t *__set) __THROW;
199 /* Add SIGNO to SET. */
200 extern int sigaddset (sigset_t *__set, int __signo) __THROW;
202 /* Remove SIGNO from SET. */
203 extern int sigdelset (sigset_t *__set, int __signo) __THROW;
205 /* Return 1 if SIGNO is in SET, 0 if not. */
206 extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
208 # ifdef __USE_GNU
209 /* Return non-empty value is SET is not empty. */
210 extern int sigisemptyset (__const sigset_t *__set) __THROW;
212 /* Build new signal set by combining the two inputs set using logical AND. */
213 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
214 __const sigset_t *__right) __THROW;
216 /* Build new signal set by combining the two inputs set using logical OR. */
217 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
218 __const sigset_t *__right) __THROW;
219 # endif /* GNU */
221 /* Get the system-specific definitions of `struct sigaction'
222 and the `SA_*' and `SIG_*'. constants. */
223 # include <bits/sigaction.h>
225 /* Get and/or change the set of blocked signals. */
226 extern int sigprocmask (int __how, __const sigset_t *__set, sigset_t *__oset)
227 __THROW;
229 /* Change the set of blocked signals to SET,
230 wait until a signal arrives, and restore the set of blocked signals. */
231 extern int sigsuspend (__const sigset_t *__set) __THROW;
233 /* Get and/or set the action for signal SIG. */
234 extern int __sigaction (int __sig, __const struct sigaction *__act,
235 struct sigaction *__oact) __THROW;
236 extern int sigaction (int __sig, __const struct sigaction *__act,
237 struct sigaction *__oact) __THROW;
239 /* Put in SET all signals that are blocked and waiting to be delivered. */
240 extern int sigpending (sigset_t *__set) __THROW;
243 /* Select any of pending signals from SET or wait for any to arrive. */
244 extern int sigwait (__const sigset_t *__set, int *__sig) __THROW;
246 # ifdef __USE_POSIX199309
247 /* Select any of pending signals from SET and place information in INFO. */
248 extern int sigwaitinfo (__const sigset_t *__set, siginfo_t *__info) __THROW;
250 /* Select any of pending signals from SET and place information in INFO.
251 Wait the imte specified by TIMEOUT if no signal is pending. */
252 extern int sigtimedwait (__const sigset_t *__set, siginfo_t *__info,
253 __const struct timespec *__timeout) __THROW;
255 /* Send signal SIG to the process PID. Associate data in VAL with the
256 signal. */
257 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
258 __THROW;
259 # endif /* Use POSIX 199306. */
261 #endif /* Use POSIX. */
263 #ifdef __USE_BSD
265 /* Names of the signals. This variable exists only for compatibility.
266 Use `strsignal' instead (see <string.h>). */
267 extern __const char *__const _sys_siglist[_NSIG];
268 extern __const char *__const sys_siglist[_NSIG];
270 /* Structure passed to `sigvec'. */
271 struct sigvec
273 __sighandler_t sv_handler; /* Signal handler. */
274 int sv_mask; /* Mask of signals to be blocked. */
276 int sv_flags; /* Flags (see below). */
277 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
280 /* Bits in `sv_flags'. */
281 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
282 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
283 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
286 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
287 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
288 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
289 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
290 it is filled in with the old information for SIG. */
291 extern int sigvec (int __sig, __const struct sigvec *__vec,
292 struct sigvec *__ovec) __THROW;
295 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
296 # include <bits/sigcontext.h>
298 /* Restore the state saved in SCP. */
299 extern int sigreturn (struct sigcontext *__scp) __THROW;
301 #endif /* use BSD. */
304 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
306 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
307 (causing them to fail with EINTR); if INTERRUPT is zero, make system
308 calls be restarted after signal SIG. */
309 extern int siginterrupt (int __sig, int __interrupt) __THROW;
311 # include <bits/sigstack.h>
313 /* Run signals handlers on the stack specified by SS (if not NULL).
314 If OSS is not NULL, it is filled in with the old signal stack status.
315 This interface is obsolete and on many platform not implemented. */
316 extern int sigstack (__const struct sigstack *__ss,
317 struct sigstack *__oss) __THROW;
319 /* Alternate signal handler stack interface.
320 This interface should always be preferred over `sigstack'. */
321 extern int sigaltstack (__const struct sigaltstack *__ss,
322 struct sigaltstack *__oss) __THROW;
324 #endif /* use BSD or X/Open Unix. */
326 #ifdef __USE_UNIX98
327 /* Simplified interface for signal management. */
329 /* Add SIG to the calling process' signal mask. */
330 extern int sighold (int __sig) __THROW;
332 /* Remove SIG from the calling process' signal mask. */
333 extern int sigrelse (int __sig) __THROW;
335 /* Set the disposition of SIG to SIG_IGN. */
336 extern int sigignore (int __sig) __THROW;
338 /* Set the disposition of SIG. */
339 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
341 /* Some of the functions for handling signals in threaded programs must
342 be defined here. */
343 # include <bits/sigthread.h>
344 #endif /* use Unix98 */
346 /* The following functions are used internally in the C library and in
347 other code which need deep insights. */
349 /* Return number of available real-time signal with highest priority. */
350 extern int __libc_current_sigrtmin (void) __THROW;
351 /* Return number of available real-time signal with lowest priority. */
352 extern int __libc_current_sigrtmax (void) __THROW;
354 #endif /* signal.h */
356 __END_DECLS
358 #endif /* not signal.h */