Update.
[platform/upstream/glibc.git] / signal / signal.h
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.
3
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.
8
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.
13
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.  */
18
19 /*
20  *      ISO C Standard: 4.7 SIGNAL HANDLING <signal.h>
21  */
22
23 #ifndef _SIGNAL_H
24
25 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
26 # define _SIGNAL_H
27 #endif
28
29 #include <features.h>
30
31 __BEGIN_DECLS
32
33 #include <bits/sigset.h>                /* __sigset_t, __sig_atomic_t.  */
34
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 1
41 typedef __sig_atomic_t sig_atomic_t;
42 # endif 
43 #endif
44
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    1
49 typedef __sigset_t sigset_t;
50 # endif
51 #endif
52
53 #ifdef _SIGNAL_H
54
55 #include <bits/types.h>
56 #include <bits/signum.h>
57
58 #if defined __USE_XOPEN && !defined pid_t
59 typedef __pid_t pid_t;
60 # define pid_t pid_t
61 #endif  /* Unix98 */
62
63
64 /* Type of a signal handler.  */
65 typedef void (*__sighandler_t) __PMT ((int));
66
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 __P ((int __sig,
71                                           __sighandler_t __handler));
72 #ifdef __USE_GNU
73 extern __sighandler_t sysv_signal __P ((int __sig, __sighandler_t __handler));
74 #endif
75
76 /* Set the handler for the signal SIG to HANDLER, returning the old
77    handler, or SIG_ERR on error.
78    By default `signal' has the BSD semantic.  */
79 #ifdef __USE_BSD
80 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
81 #else
82 /* Make sure the used `signal' implementation is the SVID version. */
83 # ifdef __REDIRECT
84 extern __sighandler_t __REDIRECT (signal,
85                                   __P ((int __sig, __sighandler_t __handler)),
86                                   __sysv_signal);
87 # else
88 #  define signal __sysv_signal
89 # endif
90 #endif
91
92 #ifdef __USE_XOPEN
93 /* The X/Open definition of `signal' conflicts with the BSD version.
94    So they defined another function `bsd_signal'.  */
95 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
96 #endif
97
98 /* Send signal SIG to process number PID.  If PID is zero,
99    send SIG to all processes in the current process's process group.
100    If PID is < -1, send SIG to all processes in process group - PID.  */
101 #ifdef __USE_POSIX
102 extern int kill __P ((__pid_t __pid, int __sig));
103 #endif /* Use POSIX.  */
104
105 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
106 /* Send SIG to all processes in process group PGRP.
107    If PGRP is zero, send SIG to all processes in
108    the current process's process group.  */
109 extern int killpg __P ((__pid_t __pgrp, int __sig));
110 #endif /* Use BSD || X/Open Unix.  */
111
112 /* Raise signal SIG, i.e., send SIG to yourself.  */
113 extern int raise __P ((int __sig));
114
115 #ifdef __USE_SVID
116 /* SVID names for the same things.  */
117 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
118 extern int gsignal __P ((int __sig));
119 #endif /* Use SVID.  */
120
121 #ifdef __USE_MISC
122 /* Print a message describing the meaning of the given signal number.  */
123 extern void psignal __P ((int __sig, __const char *__s));
124 #endif /* Use misc.  */
125
126
127 /* The `sigpause' function has two different interfaces.  The original
128    BSD definition defines the argument as a mask of the signal, while
129    the more modern interface in X/Open defines it as the signal
130    number.  We go with the BSD version unless the user explicitly
131    selects the X/Open version.  */
132 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
133
134 #ifdef __USE_BSD
135 /* Set the mask of blocked signals to MASK,
136    wait for a signal to arrive, and then restore the mask.  */
137 extern int sigpause __P ((int __mask));
138 # define sigpause(mask) __sigpause ((mask), 0)
139 #else
140 # ifdef __USE_XOPEN
141 /* Remove a signal from the signal mask and suspend the process.  */
142 #  define sigpause(sig) __sigpause ((sig), 1)
143 # endif
144 #endif
145
146
147 #ifdef __USE_BSD
148 /* None of the following functions should be used anymore.  They are here
149    only for compatibility.  A single word (`int') is not guaranteed to be
150    enough to hold a complete signal mask and therefore these functions
151    simply do not work in many situations.  Use `sigprocmask' instead.  */
152
153 /* Compute mask for signal SIG.  */
154 # define sigmask(sig)   __sigmask(sig)
155
156 /* Block signals in MASK, returning the old mask.  */
157 extern int sigblock __P ((int __mask));
158
159 /* Set the mask of blocked signals to MASK, returning the old mask.  */
160 extern int sigsetmask __P ((int __mask));
161
162 /* Return currently selected signal mask.  */
163 extern int siggetmask __P ((void));
164 #endif /* Use BSD.  */
165
166
167 #ifdef __USE_MISC
168 # define NSIG   _NSIG
169 #endif
170
171 #ifdef __USE_GNU
172 typedef __sighandler_t sighandler_t;
173 #endif
174
175 /* 4.4 BSD uses the name `sig_t' for this.  */
176 #ifdef __USE_BSD
177 typedef __sighandler_t sig_t;
178 #endif
179
180 #ifdef __USE_POSIX
181
182 # ifdef __USE_POSIX199309
183 /* We need `struct timespec' later on.  */
184 #  define __need_timespec
185 #  include <time.h>
186
187 /* Get the `siginfo_t' type plus the needed symbols.  */
188 #  include <bits/siginfo.h>
189 # endif
190
191 /* Clear all signals from SET.  */
192 extern int sigemptyset __P ((sigset_t *__set));
193
194 /* Set all signals in SET.  */
195 extern int sigfillset __P ((sigset_t *__set));
196
197 /* Add SIGNO to SET.  */
198 extern int sigaddset __P ((sigset_t *__set, int __signo));
199
200 /* Remove SIGNO from SET.  */
201 extern int sigdelset __P ((sigset_t *__set, int __signo));
202
203 /* Return 1 if SIGNO is in SET, 0 if not.  */
204 extern int sigismember __P ((__const sigset_t *__set, int __signo));
205
206 # ifdef __USE_GNU
207 /* Return non-empty value is SET is not empty.  */
208 extern int sigisemptyset __P ((__const sigset_t *__set));
209
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));
213
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 */
218
219 /* Get the system-specific definitions of `struct sigaction'
220    and the `SA_*' and `SIG_*'. constants.  */
221 # include <bits/sigaction.h>
222
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
227 /* Change the set of blocked signals to SET,
228    wait until a signal arrives, and restore the set of blocked signals.  */
229 extern int sigsuspend __P ((__const sigset_t *__set));
230
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));
236
237 /* Put in SET all signals that are blocked and waiting to be delivered.  */
238 extern int sigpending __P ((sigset_t *__set));
239
240
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
244 # ifdef __USE_POSIX199309
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
248 /* Select any of pending signals from SET and place information in INFO.
249    Wait the imte specified by TIMEOUT if no signal is pending.  */
250 extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
251                               __const struct timespec *__timeout));
252
253 /* Send signal SIG to the process PID.  Associate data in VAL with the
254    signal.  */
255 extern int sigqueue __P ((__pid_t __pid, int __sig,
256                           __const union sigval __val));
257 # endif /* Use POSIX 199306.  */
258
259 #endif /* Use POSIX.  */
260
261 #ifdef __USE_BSD
262
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];
267
268 /* Structure passed to `sigvec'.  */
269 struct sigvec
270   {
271     __sighandler_t sv_handler;  /* Signal handler.  */
272     int sv_mask;                /* Mask of signals to be blocked.  */
273
274     int sv_flags;               /* Flags (see below).  */
275 # define sv_onstack     sv_flags /* 4.2 BSD compatibility.  */
276   };
277
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.  */
282
283
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
292
293 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
294 # include <bits/sigcontext.h>
295
296 /* Restore the state saved in SCP.  */
297 extern int sigreturn __P ((struct sigcontext *__scp));
298
299 #endif /*  use BSD.  */
300
301
302 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
303
304 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
305    (causing them to fail with EINTR); if INTERRUPT is zero, make system
306    calls be restarted after signal SIG.  */
307 extern int siginterrupt __P ((int __sig, int __interrupt));
308
309 # include <bits/sigstack.h>
310
311 /* Run signals handlers on the stack specified by SS (if not NULL).
312    If OSS is not NULL, it is filled in with the old signal stack status.
313    This interface is obsolete and on many platform not implemented.  */
314 extern int sigstack __P ((__const struct sigstack *__ss,
315                           struct sigstack *__oss));
316
317 /* Alternate signal handler stack interface.
318    This interface should always be preferred over `sigstack'.  */
319 extern int sigaltstack __P ((__const struct sigaltstack *__ss,
320                              struct sigaltstack *__oss));
321
322 #endif /* use BSD or X/Open Unix.  */
323
324 #ifdef __USE_UNIX98
325 /* Simplified interface for signal management.  */
326
327 /* Add SIG to the calling process' signal mask.  */
328 extern int sighold __P ((int __sig));
329
330 /* Remove SIG from the calling process' signal mask.  */
331 extern int sigrelse __P ((int __sig));
332
333 /* Set the disposition of SIG to SIG_IGN.  */
334 extern int sigignore __P ((int __sig));
335
336 /* Set the disposition of SIG.  */
337 extern __sighandler_t sigset __P ((int __sig, __sighandler_t __disp));
338 #endif /* use Unix98 */
339
340 #ifdef __USE_POSIX199506
341 /* Some of the functions for handling signals in threaded programs must
342    be defined here.  */
343 # include <bits/sigthread.h>
344 #endif
345
346 /* The following functions are used internally in the C library and in
347    other code which need deep insights.  */
348
349 /* Return number of available real-time signal with highest priority.  */
350 extern int __libc_current_sigrtmin __P ((void));
351 /* Return number of available real-time signal with lowest priority.  */
352 extern int __libc_current_sigrtmax __P ((void));
353
354 /* Allocate real-time signal with highest/lowest available priority.  */
355 extern int __libc_allocate_rtsig __P ((int __high));
356
357 #endif /* signal.h  */
358
359 __END_DECLS
360
361 #endif /* not signal.h */