Update.
[glibc.git] / signal / signal.h
blob8a37dde0c1992b3a4b28b6a79f7afae3b0b7ae02
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));
61 #ifdef __USE_GNU
62 extern __sighandler_t sysv_signal __P ((int __sig, __sighandler_t __handler));
63 #endif
65 /* Set the handler for the signal SIG to HANDLER, returning the old
66 handler, or SIG_ERR on error.
67 By default `signal' has the BSD semantic. */
68 #ifdef __USE_BSD
69 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
70 #else
71 /* Make sure the used `signal' implementation is the SVID version. */
72 # ifdef __REDIRECT
73 extern __sighandler_t __REDIRECT (signal,
74 __P ((int __sig, __sighandler_t __handler)),
75 __sysv_signal);
76 # else
77 # define signal __sysv_signal
78 # endif
79 #endif
81 #ifdef __USE_XOPEN
82 /* The X/Open definition of `signal' conflicts with the BSD version.
83 So they defined another function `bsd_signal'. */
84 extern __sighandler_t __bsd_signal __P ((int __sig, __sighandler_t __handler));
85 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
86 #endif
88 /* Send signal SIG to process number PID. If PID is zero,
89 send SIG to all processes in the current process's process group.
90 If PID is < -1, send SIG to all processes in process group - PID. */
91 extern int __kill __P ((__pid_t __pid, int __sig));
92 #ifdef __USE_POSIX
93 extern int kill __P ((__pid_t __pid, int __sig));
94 #endif /* Use POSIX. */
96 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
97 /* Send SIG to all processes in process group PGRP.
98 If PGRP is zero, send SIG to all processes in
99 the current process's process group. */
100 extern int killpg __P ((__pid_t __pgrp, int __sig));
101 #endif /* Use BSD || X/Open Unix. */
103 /* Raise signal SIG, i.e., send SIG to yourself. */
104 extern int raise __P ((int __sig));
106 #ifdef __USE_SVID
107 /* SVID names for the same things. */
108 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
109 extern int gsignal __P ((int __sig));
110 #endif /* Use SVID. */
112 #ifdef __USE_MISC
113 /* Print a message describing the meaning of the given signal number. */
114 extern void psignal __P ((int __sig, __const char *__s));
115 #endif /* Use misc. */
118 /* Block signals in MASK, returning the old mask. */
119 extern int __sigblock __P ((int __mask));
121 /* Set the mask of blocked signals to MASK, returning the old mask. */
122 extern int __sigsetmask __P ((int __mask));
125 /* The `sigpause' function has two different interfaces. The original
126 BSD definition defines the argument as a mask of the signal, while
127 the more modern interface in X/Open defines it as the signal
128 number. We go with the BSD version unless the user explicitly
129 selects the X/Open version. */
130 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
132 #if defined __USE_BSD || defined __USE_GNU
133 /* Set the mask of blocked signals to MASK,
134 wait for a signal to arrive, and then restore the mask. */
135 extern int sigpause __P ((int __mask));
136 # define sigpause(mask) __sigpause ((mask), 0)
137 #else
138 # ifdef __USE_XOPEN
139 /* Remove a signal from the signal mask and suspend the process. */
140 # define sigpause(sig) __sigpause ((sig), 1)
141 # endif
142 #endif
145 #ifdef __USE_BSD
146 # define sigmask(sig) __sigmask(sig)
148 extern int sigblock __P ((int __mask));
149 extern int sigsetmask __P ((int __mask));
151 /* This function is here only for compatibility.
152 Use `sigprocmask' instead. */
153 extern int siggetmask __P ((void));
154 #endif /* Use BSD. */
157 #ifdef __USE_MISC
158 # define NSIG _NSIG
159 #endif
161 #ifdef __USE_GNU
162 typedef __sighandler_t sighandler_t;
163 #endif
165 /* 4.4 BSD uses the name `sig_t' for this. */
166 #ifdef __USE_BSD
167 typedef __sighandler_t sig_t;
168 #endif
170 #endif /* <signal.h> included. */
173 # if !defined __sigset_t_defined \
174 && ((defined _SIGNAL_H && defined __USE_POSIX) || defined __need_sigset_t)
175 typedef __sigset_t sigset_t;
176 # define __sigset_t_defined 1
177 # endif /* `sigset_t' not defined and <signal.h> or need `sigset_t'. */
178 # undef __need_sigset_t
180 #ifdef __USE_POSIX
182 # ifdef _SIGNAL_H
184 /* We need `struct timespec' later on. */
185 # define __need_timespec
186 # include <time.h>
188 /* Get the `siginfo_t' type plus the needed symbols. */
189 # include <bits/siginfo.h>
191 /* Clear all signals from SET. */
192 extern int sigemptyset __P ((sigset_t *__set));
194 /* Set all signals in SET. */
195 extern int sigfillset __P ((sigset_t *__set));
197 /* Add SIGNO to SET. */
198 extern int sigaddset __P ((sigset_t *__set, int __signo));
200 /* Remove SIGNO from SET. */
201 extern int sigdelset __P ((sigset_t *__set, int __signo));
203 /* Return 1 if SIGNO is in SET, 0 if not. */
204 extern int sigismember __P ((__const sigset_t *__set, int __signo));
206 # ifdef __USE_GNU
207 /* Return non-empty value is SET is not empty. */
208 extern int sigisemptyset __P ((__const sigset_t *__set));
210 /* Build new signal set by combining the two inputs set using logical AND. */
211 extern int sigandset __P ((sigset_t *__set, __const sigset_t *__left,
212 __const sigset_t *__right));
214 /* Build new signal set by combining the two inputs set using logical OR. */
215 extern int sigorset __P ((sigset_t *__set, __const sigset_t *__left,
216 __const sigset_t *__right));
217 # endif /* GNU */
219 /* Get the system-specific definitions of `struct sigaction'
220 and the `SA_*' and `SIG_*'. constants. */
221 # include <bits/sigaction.h>
223 /* Get and/or change the set of blocked signals. */
224 extern int __sigprocmask __P ((int __how,
225 __const sigset_t *__set, sigset_t *__oset));
226 extern int sigprocmask __P ((int __how,
227 __const sigset_t *__set, sigset_t *__oset));
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 __P ((__const sigset_t *__set));
232 extern int sigsuspend __P ((__const sigset_t *__set));
234 /* Get and/or set the action for signal SIG. */
235 extern int __sigaction __P ((int __sig, __const struct sigaction *__act,
236 struct sigaction *__oact));
237 extern int sigaction __P ((int __sig, __const struct sigaction *__act,
238 struct sigaction *__oact));
240 /* Put in SET all signals that are blocked and waiting to be delivered. */
241 extern int sigpending __P ((sigset_t *__set));
244 /* Select any of pending signals from SET or wait for any to arrive. */
245 extern int __sigwait __P ((__const sigset_t *__set, int *__sig));
246 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
248 /* Select any of pending signals from SET and place information in INFO. */
249 extern int __sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
250 extern int sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
252 /* Select any of pending signals from SET and place information in INFO.
253 Wait the imte specified by TIMEOUT if no signal is pending. */
254 extern int __sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
255 __const struct timespec *__timeout));
256 extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
257 __const struct timespec *__timeout));
259 /* Send signal SIG to the process PID. Associate data in VAL with the
260 signal. */
261 extern int __sigqueue __P ((__pid_t __pid, int __sig,
262 __const union sigval __val));
263 extern int sigqueue __P ((__pid_t __pid, int __sig,
264 __const union sigval __val));
266 # endif /* <signal.h> included. */
268 #endif /* Use POSIX. */
270 #if defined _SIGNAL_H && defined __USE_BSD
272 /* Names of the signals. This variable exists only for compatibility.
273 Use `strsignal' instead (see <string.h>). */
274 extern __const char *__const _sys_siglist[_NSIG];
275 extern __const char *__const sys_siglist[_NSIG];
277 /* Structure passed to `sigvec'. */
278 struct sigvec
280 __sighandler_t sv_handler; /* Signal handler. */
281 int sv_mask; /* Mask of signals to be blocked. */
283 int sv_flags; /* Flags (see below). */
284 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
287 /* Bits in `sv_flags'. */
288 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
289 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
290 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
293 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
294 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
295 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
296 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
297 it is filled in with the old information for SIG. */
298 extern int __sigvec __P ((int __sig, __const struct sigvec *__vec,
299 struct sigvec *__ovec));
300 extern int sigvec __P ((int __sig, __const struct sigvec *__vec,
301 struct sigvec *__ovec));
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 __P ((struct sigcontext *__scp));
309 extern int sigreturn __P ((struct sigcontext *__scp));
311 #endif /* signal.h included and use BSD. */
314 #if defined _SIGNAL_H && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
316 # define __need_size_t
317 # include <stddef.h>
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 __P ((int __sig, int __interrupt));
324 # include <bits/sigstack.h>
326 /* Run signals handlers on the stack specified by SS (if not NULL).
327 If OSS is not NULL, it is filled in with the old signal stack status.
328 This interface is obsolete and on many platform not implemented. */
329 extern int sigstack __P ((__const struct sigstack *__ss,
330 struct sigstack *__oss));
332 /* Alternate signal handler stack interface.
333 This interface should always be preferred over `sigstack'. */
334 extern int __sigaltstack __P ((__const struct sigaltstack *__ss,
335 struct sigaltstack *__oss));
336 extern int sigaltstack __P ((__const struct sigaltstack *__ss,
337 struct sigaltstack *__oss));
339 #endif /* signal.h included and use BSD or X/Open Unix. */
342 #if defined _SIGNAL_H && defined __USE_UNIX98
343 /* Simplified interface for signal management. */
345 /* Add SIG to the calling process' signal mask. */
346 extern int sighold __P ((int __sig));
348 /* Remove SIG from the calling process' signal mask. */
349 extern int sigrelse __P ((int __sig));
351 /* Set the disposition of SIG to SIG_IGN. */
352 extern int sigignore __P ((int __sig));
354 /* Set the disposition of SIG. */
355 extern __sighandler_t sigset __P ((int __sig, __sighandler_t __disp));
356 #endif
358 /* Some of the functions for handling signals in threaded programs must
359 be defined here. */
360 #include <bits/sigthread.h>
362 /* The following functions are used internally in the C library and in
363 other code which need deep insights. */
365 /* Return number of available real-time signal with highest priority. */
366 extern int __libc_current_sigrtmin __P ((void));
367 /* Return number of available real-time signal with lowest priority. */
368 extern int __libc_current_sigrtmax __P ((void));
370 /* Allocate real-time signal with highest/lowest available priority. */
371 extern int __libc_allocate_rtsig __P ((int __high));
373 __END_DECLS
375 #endif /* signal.h */