Update.
[glibc.git] / signal / signal.h
blob11b6565be685d21f4487fff23feaa91dfdcf7b85
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 __sig_atomic_t_defined \
36 && (defined _SIGNAL_H || defined __need_sig_atomic_t)
37 /* An integral type that can be modified atomically, without the
38 possibility of a signal arriving in the middle of the operation. */
39 typedef __sig_atomic_t sig_atomic_t;
40 #endif /* `sig_atomic_t' undefined and <signal.h> or need `sig_atomic_t'. */
41 #undef __need_sig_atomic_t
43 #ifdef _SIGNAL_H
45 #include <bits/signum.h>
47 /* Type of a signal handler. */
48 typedef void (*__sighandler_t) __P ((int));
50 /* The X/Open definition of `signal' specifies the SVID semantic. Use
51 the additional function `sysv_signal' when X/Open compatibility is
52 requested. */
53 extern __sighandler_t __sysv_signal __P ((int __sig,
54 __sighandler_t __handler));
56 /* Set the handler for the signal SIG to HANDLER, returning the old
57 handler, or SIG_ERR on error.
58 By default `signal' has the BSD semantic. */
59 #ifdef __USE_BSD
60 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
61 #else
62 /* Make sure the used `signal' implementation is the SVID version.
63 When GNU CC is used we have a clean way to write this. */
64 # if defined __GNUC__ && __GNUC__ >= 2
65 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler))
66 __asm__ ("__sysv_signal");
67 # else
68 # define signal(sig, handler) __sysv_signal ((sig), (handler))
69 # endif
70 #endif
72 #ifdef __USE_XOPEN
73 /* The X/Open definition of `signal' conflicts with the BSD version.
74 So they defined another function `bsd_signal'. */
75 extern __sighandler_t __bsd_signal __P ((int __sig, __sighandler_t __handler));
76 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
77 #endif
79 /* Send signal SIG to process number PID. If PID is zero,
80 send SIG to all processes in the current process's process group.
81 If PID is < -1, send SIG to all processes in process group - PID. */
82 extern int __kill __P ((__pid_t __pid, int __sig));
83 #ifdef __USE_POSIX
84 extern int kill __P ((__pid_t __pid, int __sig));
85 #endif /* Use POSIX. */
87 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
88 /* Send SIG to all processes in process group PGRP.
89 If PGRP is zero, send SIG to all processes in
90 the current process's process group. */
91 extern int killpg __P ((__pid_t __pgrp, int __sig));
92 #endif /* Use BSD || X/Open Unix. */
94 /* Raise signal SIG, i.e., send SIG to yourself. */
95 extern int raise __P ((int __sig));
97 #ifdef __USE_SVID
98 /* SVID names for the same things. */
99 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
100 extern int gsignal __P ((int __sig));
101 #endif /* Use SVID. */
103 #ifdef __USE_MISC
104 /* Print a message describing the meaning of the given signal number. */
105 extern void psignal __P ((int __sig, __const char *__s));
106 #endif /* Use misc. */
109 /* Block signals in MASK, returning the old mask. */
110 extern int __sigblock __P ((int __mask));
112 /* Set the mask of blocked signals to MASK, returning the old mask. */
113 extern int __sigsetmask __P ((int __mask));
116 /* The `sigpause' function has two different interfaces. The original
117 BSD definition defines the argument as a mask of the signal, while
118 the more modern interface in X/Open defines it as the signal
119 number. We go with the BSD version unless the user explicitly
120 selects the X/Open version. */
121 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
123 #if defined __USE_BSD || defined __USE_GNU
124 /* Set the mask of blocked signals to MASK,
125 wait for a signal to arrive, and then restore the mask. */
126 extern int sigpause __P ((int __mask));
127 # define sigpause(mask) __sigpause ((mask), 0)
128 #else
129 # ifdef __USE_XOPEN
130 /* Remove a signal from the signal mask and suspend the process. */
131 # define sigpause(sig) __sigpause ((sig), 1)
132 # endif
133 #endif
136 #ifdef __USE_BSD
137 # define sigmask(sig) __sigmask(sig)
139 extern int sigblock __P ((int __mask));
140 extern int sigsetmask __P ((int __mask));
142 /* This function is here only for compatibility.
143 Use `sigprocmask' instead. */
144 extern int siggetmask __P ((void));
145 #endif /* Use BSD. */
148 #ifdef __USE_MISC
149 # define NSIG _NSIG
150 #endif
152 #ifdef __USE_GNU
153 typedef __sighandler_t sighandler_t;
154 #endif
156 /* 4.4 BSD uses the name `sig_t' for this. */
157 #ifdef __USE_BSD
158 typedef __sighandler_t sig_t;
159 #endif
161 #endif /* <signal.h> included. */
164 #ifdef __USE_POSIX
166 # if !defined __sigset_t_defined \
167 && (defined _SIGNAL_H || defined __need_sigset_t)
168 typedef __sigset_t sigset_t;
169 # define __sigset_t_defined 1
170 # endif /* `sigset_t' not defined and <signal.h> or need `sigset_t'. */
171 # undef __need_sigset_t
173 # ifdef _SIGNAL_H
175 /* We need `struct timespec' later on. */
176 # define __need_timespec
177 # include <time.h>
179 /* Get the `siginfo_t' type plus the needed symbols. */
180 # include <bits/siginfo.h>
182 /* Clear all signals from SET. */
183 extern int sigemptyset __P ((sigset_t *__set));
185 /* Set all signals in SET. */
186 extern int sigfillset __P ((sigset_t *__set));
188 /* Add SIGNO to SET. */
189 extern int sigaddset __P ((sigset_t *__set, int __signo));
191 /* Remove SIGNO from SET. */
192 extern int sigdelset __P ((sigset_t *__set, int __signo));
194 /* Return 1 if SIGNO is in SET, 0 if not. */
195 extern int sigismember __P ((__const sigset_t *__set, int __signo));
197 # ifdef __USE_GNU
198 /* Return non-empty value is SET is not empty. */
199 extern int sigisemptyset __P ((__const sigset_t *__set));
201 /* Build new signal set by combining the two inputs set using logical AND. */
202 extern int sigandset __P ((sigset_t *__set, __const sigset_t *__left,
203 __const sigset_t *__right));
205 /* Build new signal set by combining the two inputs set using logical OR. */
206 extern int sigorset __P ((sigset_t *__set, __const sigset_t *__left,
207 __const sigset_t *__right));
208 # endif /* GNU */
210 /* Get the system-specific definitions of `struct sigaction'
211 and the `SA_*' and `SIG_*'. constants. */
212 # include <bits/sigaction.h>
214 /* Get and/or change the set of blocked signals. */
215 extern int __sigprocmask __P ((int __how,
216 __const sigset_t *__set, sigset_t *__oset));
217 extern int sigprocmask __P ((int __how,
218 __const sigset_t *__set, sigset_t *__oset));
220 /* Change the set of blocked signals to SET,
221 wait until a signal arrives, and restore the set of blocked signals. */
222 extern int __sigsuspend __P ((__const sigset_t *__set));
223 extern int sigsuspend __P ((__const sigset_t *__set));
225 /* Get and/or set the action for signal SIG. */
226 extern int __sigaction __P ((int __sig, __const struct sigaction *__act,
227 struct sigaction *__oact));
228 extern int sigaction __P ((int __sig, __const struct sigaction *__act,
229 struct sigaction *__oact));
231 /* Put in SET all signals that are blocked and waiting to be delivered. */
232 extern int sigpending __P ((sigset_t *__set));
235 /* Select any of pending signals from SET or wait for any to arrive. */
236 extern int __sigwait __P ((__const sigset_t *__set, int *__sig));
237 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
239 /* Select any of pending signals from SET and place information in INFO. */
240 extern int __sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
241 extern int sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
243 /* Select any of pending signals from SET and place information in INFO.
244 Wait the imte specified by TIMEOUT if no signal is pending. */
245 extern int __sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
246 __const struct timespec *__timeout));
247 extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
248 __const struct timespec *__timeout));
250 /* Send signal SIG to the process PID. Associate data in VAL with the
251 signal. */
252 extern int __sigqueue __P ((__pid_t __pid, int __sig,
253 __const union sigval __val));
254 extern int sigqueue __P ((__pid_t __pid, int __sig,
255 __const union sigval __val));
257 # endif /* <signal.h> included. */
259 #endif /* Use POSIX. */
261 #if defined _SIGNAL_H && defined __USE_BSD
263 /* Names of the signals. This variable exists only for compatibility.
264 Use `strsignal' instead (see <string.h>). */
265 extern __const char *__const _sys_siglist[_NSIG];
266 extern __const char *__const sys_siglist[_NSIG];
268 /* Structure passed to `sigvec'. */
269 struct sigvec
271 __sighandler_t sv_handler; /* Signal handler. */
272 int sv_mask; /* Mask of signals to be blocked. */
274 int sv_flags; /* Flags (see below). */
275 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
278 /* Bits in `sv_flags'. */
279 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
280 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
281 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
284 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
285 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
286 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
287 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
288 it is filled in with the old information for SIG. */
289 extern int __sigvec __P ((int __sig, __const struct sigvec *__vec,
290 struct sigvec *__ovec));
291 extern int sigvec __P ((int __sig, __const struct sigvec *__vec,
292 struct sigvec *__ovec));
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 __P ((struct sigcontext *__scp));
300 extern int sigreturn __P ((struct sigcontext *__scp));
302 #endif /* signal.h included and use BSD. */
305 #if defined _SIGNAL_H && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
307 # define __need_size_t
308 # include <stddef.h>
310 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
311 (causing them to fail with EINTR); if INTERRUPT is zero, make system
312 calls be restarted after signal SIG. */
313 extern int siginterrupt __P ((int __sig, int __interrupt));
316 /* Structure describing a signal stack. */
317 struct sigstack
319 __ptr_t ss_sp; /* Signal stack pointer. */
320 int ss_onstack; /* Nonzero if executing on this stack. */
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 extern int sigstack __P ((__const struct sigstack *__ss,
326 struct sigstack *__oss));
328 /* Alternate interface. */
329 typedef struct sigaltstack
331 __ptr_t ss_sp;
332 size_t ss_size;
333 int ss_flags;
334 } stack_t;
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 /* The following functions are used internally in the C library and in
343 other code which need deep insights. */
345 /* Return number of available real-time signal with highest priority. */
346 extern int __libc_current_sigrtmin __P ((void));
347 /* Return number of available real-time signal with lowest priority. */
348 extern int __libc_current_sigrtmax __P ((void));
350 /* Allocate real-time signal with highest/lowest available priority. */
351 extern int __libc_allocate_rtsig __P ((int __high));
353 __END_DECLS
355 #endif /* signal.h */