Update.
[glibc.git] / signal / signal.h
blob5d6337594708170291b3256eb7ae00313c2c3479
1 /* Copyright (C) 1991,92,93,94,95,96,97,98 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 1
27 # include <features.h>
28 #endif
30 __BEGIN_DECLS
32 #include <bits/types.h>
33 #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
35 #if defined _SIGNAL_H && defined __USE_XOPEN && !defined pid_t
36 typedef __pid_t pid_t;
37 # define pid_t pid_t
38 #endif /* Unix98 */
40 #if !defined __sig_atomic_t_defined \
41 && (defined _SIGNAL_H || defined __need_sig_atomic_t)
42 /* An integral type that can be modified atomically, without the
43 possibility of a signal arriving in the middle of the operation. */
44 typedef __sig_atomic_t sig_atomic_t;
45 # define __sig_atomic_t_defined
46 #endif /* `sig_atomic_t' undefined and <signal.h> or need `sig_atomic_t'. */
47 #undef __need_sig_atomic_t
49 #ifdef _SIGNAL_H
51 #include <bits/signum.h>
53 /* Type of a signal handler. */
54 typedef void (*__sighandler_t) __PMT ((int));
56 /* The X/Open definition of `signal' specifies the SVID semantic. Use
57 the additional function `sysv_signal' when X/Open compatibility is
58 requested. */
59 extern __sighandler_t __sysv_signal __P ((int __sig,
60 __sighandler_t __handler));
62 /* Set the handler for the signal SIG to HANDLER, returning the old
63 handler, or SIG_ERR on error.
64 By default `signal' has the BSD semantic. */
65 #ifdef __USE_BSD
66 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
67 #else
68 /* Make sure the used `signal' implementation is the SVID version. */
69 # ifdef __REDIRECT
70 extern __sighandler_t __REDIRECT (signal,
71 __P ((int __sig, __sighandler_t __handler)),
72 __sysv_signal);
73 # else
74 # define signal __sysv_signal
75 # endif
76 #endif
78 #ifdef __USE_XOPEN
79 /* The X/Open definition of `signal' conflicts with the BSD version.
80 So they defined another function `bsd_signal'. */
81 extern __sighandler_t __bsd_signal __P ((int __sig, __sighandler_t __handler));
82 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
83 #endif
85 /* Send signal SIG to process number PID. If PID is zero,
86 send SIG to all processes in the current process's process group.
87 If PID is < -1, send SIG to all processes in process group - PID. */
88 extern int __kill __P ((__pid_t __pid, int __sig));
89 #ifdef __USE_POSIX
90 extern int kill __P ((__pid_t __pid, int __sig));
91 #endif /* Use POSIX. */
93 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
94 /* Send SIG to all processes in process group PGRP.
95 If PGRP is zero, send SIG to all processes in
96 the current process's process group. */
97 extern int killpg __P ((__pid_t __pgrp, int __sig));
98 #endif /* Use BSD || X/Open Unix. */
100 /* Raise signal SIG, i.e., send SIG to yourself. */
101 extern int raise __P ((int __sig));
103 #ifdef __USE_SVID
104 /* SVID names for the same things. */
105 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
106 extern int gsignal __P ((int __sig));
107 #endif /* Use SVID. */
109 #ifdef __USE_MISC
110 /* Print a message describing the meaning of the given signal number. */
111 extern void psignal __P ((int __sig, __const char *__s));
112 #endif /* Use misc. */
115 /* Block signals in MASK, returning the old mask. */
116 extern int __sigblock __P ((int __mask));
118 /* Set the mask of blocked signals to MASK, returning the old mask. */
119 extern int __sigsetmask __P ((int __mask));
122 /* The `sigpause' function has two different interfaces. The original
123 BSD definition defines the argument as a mask of the signal, while
124 the more modern interface in X/Open defines it as the signal
125 number. We go with the BSD version unless the user explicitly
126 selects the X/Open version. */
127 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
129 #if defined __USE_BSD || defined __USE_GNU
130 /* Set the mask of blocked signals to MASK,
131 wait for a signal to arrive, and then restore the mask. */
132 extern int sigpause __P ((int __mask));
133 # define sigpause(mask) __sigpause ((mask), 0)
134 #else
135 # ifdef __USE_XOPEN
136 /* Remove a signal from the signal mask and suspend the process. */
137 # define sigpause(sig) __sigpause ((sig), 1)
138 # endif
139 #endif
142 #ifdef __USE_BSD
143 # define sigmask(sig) __sigmask(sig)
145 extern int sigblock __P ((int __mask));
146 extern int sigsetmask __P ((int __mask));
148 /* This function is here only for compatibility.
149 Use `sigprocmask' instead. */
150 extern int siggetmask __P ((void));
151 #endif /* Use BSD. */
154 #ifdef __USE_MISC
155 # define NSIG _NSIG
156 #endif
158 #ifdef __USE_GNU
159 typedef __sighandler_t sighandler_t;
160 #endif
162 /* 4.4 BSD uses the name `sig_t' for this. */
163 #ifdef __USE_BSD
164 typedef __sighandler_t sig_t;
165 #endif
167 #endif /* <signal.h> included. */
170 # if !defined __sigset_t_defined \
171 && ((defined _SIGNAL_H && defined __USE_POSIX) || defined __need_sigset_t)
172 typedef __sigset_t sigset_t;
173 # define __sigset_t_defined 1
174 # endif /* `sigset_t' not defined and <signal.h> or need `sigset_t'. */
175 # undef __need_sigset_t
177 #ifdef __USE_POSIX
179 # ifdef _SIGNAL_H
181 /* We need `struct timespec' later on. */
182 # define __need_timespec
183 # include <time.h>
185 /* Get the `siginfo_t' type plus the needed symbols. */
186 # include <bits/siginfo.h>
188 /* Clear all signals from SET. */
189 extern int sigemptyset __P ((sigset_t *__set));
191 /* Set all signals in SET. */
192 extern int sigfillset __P ((sigset_t *__set));
194 /* Add SIGNO to SET. */
195 extern int sigaddset __P ((sigset_t *__set, int __signo));
197 /* Remove SIGNO from SET. */
198 extern int sigdelset __P ((sigset_t *__set, int __signo));
200 /* Return 1 if SIGNO is in SET, 0 if not. */
201 extern int sigismember __P ((__const sigset_t *__set, int __signo));
203 # ifdef __USE_GNU
204 /* Return non-empty value is SET is not empty. */
205 extern int sigisemptyset __P ((__const sigset_t *__set));
207 /* Build new signal set by combining the two inputs set using logical AND. */
208 extern int sigandset __P ((sigset_t *__set, __const sigset_t *__left,
209 __const sigset_t *__right));
211 /* Build new signal set by combining the two inputs set using logical OR. */
212 extern int sigorset __P ((sigset_t *__set, __const sigset_t *__left,
213 __const sigset_t *__right));
214 # endif /* GNU */
216 /* Get the system-specific definitions of `struct sigaction'
217 and the `SA_*' and `SIG_*'. constants. */
218 # include <bits/sigaction.h>
220 /* Get and/or change the set of blocked signals. */
221 extern int __sigprocmask __P ((int __how,
222 __const sigset_t *__set, sigset_t *__oset));
223 extern int sigprocmask __P ((int __how,
224 __const sigset_t *__set, sigset_t *__oset));
226 /* Change the set of blocked signals to SET,
227 wait until a signal arrives, and restore the set of blocked signals. */
228 extern int __sigsuspend __P ((__const sigset_t *__set));
229 extern int sigsuspend __P ((__const sigset_t *__set));
231 /* Get and/or set the action for signal SIG. */
232 extern int __sigaction __P ((int __sig, __const struct sigaction *__act,
233 struct sigaction *__oact));
234 extern int sigaction __P ((int __sig, __const struct sigaction *__act,
235 struct sigaction *__oact));
237 /* Put in SET all signals that are blocked and waiting to be delivered. */
238 extern int sigpending __P ((sigset_t *__set));
241 /* Select any of pending signals from SET or wait for any to arrive. */
242 extern int __sigwait __P ((__const sigset_t *__set, int *__sig));
243 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
245 /* Select any of pending signals from SET and place information in INFO. */
246 extern int __sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
247 extern int sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
249 /* Select any of pending signals from SET and place information in INFO.
250 Wait the imte specified by TIMEOUT if no signal is pending. */
251 extern int __sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
252 __const struct timespec *__timeout));
253 extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
254 __const struct timespec *__timeout));
256 /* Send signal SIG to the process PID. Associate data in VAL with the
257 signal. */
258 extern int __sigqueue __P ((__pid_t __pid, int __sig,
259 __const union sigval __val));
260 extern int sigqueue __P ((__pid_t __pid, int __sig,
261 __const union sigval __val));
263 # endif /* <signal.h> included. */
265 #endif /* Use POSIX. */
267 #if defined _SIGNAL_H && defined __USE_BSD
269 /* Names of the signals. This variable exists only for compatibility.
270 Use `strsignal' instead (see <string.h>). */
271 extern __const char *__const _sys_siglist[_NSIG];
272 extern __const char *__const sys_siglist[_NSIG];
274 /* Structure passed to `sigvec'. */
275 struct sigvec
277 __sighandler_t sv_handler; /* Signal handler. */
278 int sv_mask; /* Mask of signals to be blocked. */
280 int sv_flags; /* Flags (see below). */
281 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
284 /* Bits in `sv_flags'. */
285 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
286 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
287 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
290 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
291 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
292 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
293 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
294 it is filled in with the old information for SIG. */
295 extern int __sigvec __P ((int __sig, __const struct sigvec *__vec,
296 struct sigvec *__ovec));
297 extern int sigvec __P ((int __sig, __const struct sigvec *__vec,
298 struct sigvec *__ovec));
301 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
302 # include <bits/sigcontext.h>
304 /* Restore the state saved in SCP. */
305 extern int __sigreturn __P ((struct sigcontext *__scp));
306 extern int sigreturn __P ((struct sigcontext *__scp));
308 #endif /* signal.h included and use BSD. */
311 #if defined _SIGNAL_H && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
313 # define __need_size_t
314 # include <stddef.h>
316 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
317 (causing them to fail with EINTR); if INTERRUPT is zero, make system
318 calls be restarted after signal SIG. */
319 extern int siginterrupt __P ((int __sig, int __interrupt));
321 # include <bits/sigstack.h>
323 /* Run signals handlers on the stack specified by SS (if not NULL).
324 If OSS is not NULL, it is filled in with the old signal stack status.
325 This interface is obsolete and on many platform not implemented. */
326 extern int sigstack __P ((__const struct sigstack *__ss,
327 struct sigstack *__oss));
329 /* Alternate signal handler stack interface.
330 This interface should always be preferred over `sigstack'. */
331 extern int __sigaltstack __P ((__const struct sigaltstack *__ss,
332 struct sigaltstack *__oss));
333 extern int sigaltstack __P ((__const struct sigaltstack *__ss,
334 struct sigaltstack *__oss));
336 #endif /* signal.h included and use BSD or X/Open Unix. */
339 #if defined _SIGNAL_H && defined __USE_UNIX98
340 /* Simplified interface for signal management. */
342 /* Add SIG to the calling process' signal mask. */
343 extern int sighold __P ((int __sig));
345 /* Remove SIG from the calling process' signal mask. */
346 extern int sigrelse __P ((int __sig));
348 /* Set the disposition of SIG to SIG_IGN. */
349 extern int sigignore __P ((int __sig));
351 /* Set the disposition of SIG. */
352 extern __sighandler_t sigset __P ((int __sig, __sighandler_t __disp));
353 #endif
355 /* Some of the functions for handling signals in threaded programs must
356 be defined here. */
357 #include <bits/sigthread.h>
359 /* The following functions are used internally in the C library and in
360 other code which need deep insights. */
362 /* Return number of available real-time signal with highest priority. */
363 extern int __libc_current_sigrtmin __P ((void));
364 /* Return number of available real-time signal with lowest priority. */
365 extern int __libc_current_sigrtmax __P ((void));
367 /* Allocate real-time signal with highest/lowest available priority. */
368 extern int __libc_allocate_rtsig __P ((int __high));
370 __END_DECLS
372 #endif /* signal.h */