Update.
[platform/upstream/glibc.git] / signal / signal.h
1 /* Copyright (C) 1991-1999,2000,2001,2002,2003 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 Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the 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    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 /*
20  *      ISO C99 Standard: 7.14 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 #if defined __need_sig_atomic_t || defined _SIGNAL_H
38 # ifndef __sig_atomic_t_defined
39 #  define __sig_atomic_t_defined
40 __BEGIN_NAMESPACE_STD
41 typedef __sig_atomic_t sig_atomic_t;
42 __END_NAMESPACE_STD
43 # endif
44 # undef __need_sig_atomic_t
45 #endif
46
47 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
48 # ifndef __sigset_t_defined
49 #  define __sigset_t_defined
50 typedef __sigset_t sigset_t;
51 # endif
52 # undef __need_sigset_t
53 #endif
54
55 #ifdef _SIGNAL_H
56
57 #include <bits/types.h>
58 #include <bits/signum.h>
59
60 #ifdef __USE_XOPEN
61 # ifndef __pid_t_defined
62 typedef __pid_t pid_t;
63 #  define __pid_t_defined
64 # endif
65 # ifndef __uid_t_defined
66 typedef __uid_t uid_t;
67 #  define __uid_t_defined
68 # endif
69 #endif  /* Unix98 */
70
71
72 /* Type of a signal handler.  */
73 typedef void (*__sighandler_t) (int);
74
75 /* The X/Open definition of `signal' specifies the SVID semantic.  Use
76    the additional function `sysv_signal' when X/Open compatibility is
77    requested.  */
78 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
79      __THROW;
80 #ifdef __USE_GNU
81 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
82      __THROW;
83 #endif
84
85 /* Set the handler for the signal SIG to HANDLER, returning the old
86    handler, or SIG_ERR on error.
87    By default `signal' has the BSD semantic.  */
88 __BEGIN_NAMESPACE_STD
89 #ifdef __USE_BSD
90 extern __sighandler_t signal (int __sig, __sighandler_t __handler) __THROW;
91 #else
92 /* Make sure the used `signal' implementation is the SVID version. */
93 # ifdef __REDIRECT
94 extern __sighandler_t __REDIRECT (signal,
95                                   (int __sig,
96                                    __sighandler_t __handler) __THROW,
97                                   __sysv_signal);
98 # else
99 #  define signal __sysv_signal
100 # endif
101 #endif
102 __END_NAMESPACE_STD
103
104 #ifdef __USE_XOPEN
105 /* The X/Open definition of `signal' conflicts with the BSD version.
106    So they defined another function `bsd_signal'.  */
107 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) __THROW;
108 #endif
109
110 /* Send signal SIG to process number PID.  If PID is zero,
111    send SIG to all processes in the current process's process group.
112    If PID is < -1, send SIG to all processes in process group - PID.  */
113 #ifdef __USE_POSIX
114 extern int kill (__pid_t __pid, int __sig) __THROW;
115 #endif /* Use POSIX.  */
116
117 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
118 /* Send SIG to all processes in process group PGRP.
119    If PGRP is zero, send SIG to all processes in
120    the current process's process group.  */
121 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
122 #endif /* Use BSD || X/Open Unix.  */
123
124 __BEGIN_NAMESPACE_STD
125 /* Raise signal SIG, i.e., send SIG to yourself.  */
126 extern int raise (int __sig) __THROW;
127 __END_NAMESPACE_STD
128
129 #ifdef __USE_SVID
130 /* SVID names for the same things.  */
131 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __THROW;
132 extern int gsignal (int __sig) __THROW;
133 #endif /* Use SVID.  */
134
135 #ifdef __USE_MISC
136 /* Print a message describing the meaning of the given signal number.  */
137 extern void psignal (int __sig, __const char *__s) __THROW;
138 #endif /* Use misc.  */
139
140
141 /* The `sigpause' function has two different interfaces.  The original
142    BSD definition defines the argument as a mask of the signal, while
143    the more modern interface in X/Open defines it as the signal
144    number.  We go with the BSD version unless the user explicitly
145    selects the X/Open version.
146
147    This function is a cancellation point and therefore not marked with
148    __THROW.  */
149 extern int __sigpause (int __sig_or_mask, int __is_sig);
150
151 #ifdef __USE_BSD
152 /* Set the mask of blocked signals to MASK,
153    wait for a signal to arrive, and then restore the mask.  */
154 extern int sigpause (int __mask) __THROW;
155 # define sigpause(mask) __sigpause ((mask), 0)
156 #else
157 # ifdef __USE_XOPEN
158 #  ifdef __GNUC__
159 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
160 #  endif
161 /* Remove a signal from the signal mask and suspend the process.  */
162 #  define sigpause(sig) __sigpause ((sig), 1)
163 # endif
164 #endif
165
166
167 #ifdef __USE_BSD
168 /* None of the following functions should be used anymore.  They are here
169    only for compatibility.  A single word (`int') is not guaranteed to be
170    enough to hold a complete signal mask and therefore these functions
171    simply do not work in many situations.  Use `sigprocmask' instead.  */
172
173 /* Compute mask for signal SIG.  */
174 # define sigmask(sig)   __sigmask(sig)
175
176 /* Block signals in MASK, returning the old mask.  */
177 extern int sigblock (int __mask) __THROW;
178
179 /* Set the mask of blocked signals to MASK, returning the old mask.  */
180 extern int sigsetmask (int __mask) __THROW;
181
182 /* Return currently selected signal mask.  */
183 extern int siggetmask (void) __THROW;
184 #endif /* Use BSD.  */
185
186
187 #ifdef __USE_MISC
188 # define NSIG   _NSIG
189 #endif
190
191 #ifdef __USE_GNU
192 typedef __sighandler_t sighandler_t;
193 #endif
194
195 /* 4.4 BSD uses the name `sig_t' for this.  */
196 #ifdef __USE_BSD
197 typedef __sighandler_t sig_t;
198 #endif
199
200 #ifdef __USE_POSIX
201
202 # ifdef __USE_POSIX199309
203 /* We need `struct timespec' later on.  */
204 #  define __need_timespec
205 #  include <time.h>
206
207 /* Get the `siginfo_t' type plus the needed symbols.  */
208 #  include <bits/siginfo.h>
209 # endif
210
211 /* Clear all signals from SET.  */
212 extern int sigemptyset (sigset_t *__set) __THROW;
213
214 /* Set all signals in SET.  */
215 extern int sigfillset (sigset_t *__set) __THROW;
216
217 /* Add SIGNO to SET.  */
218 extern int sigaddset (sigset_t *__set, int __signo) __THROW;
219
220 /* Remove SIGNO from SET.  */
221 extern int sigdelset (sigset_t *__set, int __signo) __THROW;
222
223 /* Return 1 if SIGNO is in SET, 0 if not.  */
224 extern int sigismember (__const sigset_t *__set, int __signo) __THROW;
225
226 # ifdef __USE_GNU
227 /* Return non-empty value is SET is not empty.  */
228 extern int sigisemptyset (__const sigset_t *__set) __THROW;
229
230 /* Build new signal set by combining the two inputs set using logical AND.  */
231 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
232                       __const sigset_t *__right) __THROW;
233
234 /* Build new signal set by combining the two inputs set using logical OR.  */
235 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
236                      __const sigset_t *__right) __THROW;
237 # endif /* GNU */
238
239 /* Get the system-specific definitions of `struct sigaction'
240    and the `SA_*' and `SIG_*'. constants.  */
241 # include <bits/sigaction.h>
242
243 /* Get and/or change the set of blocked signals.  */
244 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
245                         sigset_t *__restrict __oset) __THROW;
246
247 /* Change the set of blocked signals to SET,
248    wait until a signal arrives, and restore the set of blocked signals.
249
250    This function is a cancellation point and therefore not marked with
251    __THROW.  */
252 extern int sigsuspend (__const sigset_t *__set);
253
254 /* Get and/or set the action for signal SIG.  */
255 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
256                       struct sigaction *__restrict __oact) __THROW;
257
258 /* Put in SET all signals that are blocked and waiting to be delivered.  */
259 extern int sigpending (sigset_t *__set) __THROW;
260
261
262 /* Select any of pending signals from SET or wait for any to arrive.
263
264    This function is a cancellation point and therefore not marked with
265    __THROW.  */
266 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig);
267
268 # ifdef __USE_POSIX199309
269 /* Select any of pending signals from SET and place information in INFO.
270
271    This function is a cancellation point and therefore not marked with
272    __THROW.  */
273 extern int sigwaitinfo (__const sigset_t *__restrict __set,
274                         siginfo_t *__restrict __info);
275
276 /* Select any of pending signals from SET and place information in INFO.
277    Wait the time specified by TIMEOUT if no signal is pending.
278
279    This function is a cancellation point and therefore not marked with
280    __THROW.  */
281 extern int sigtimedwait (__const sigset_t *__restrict __set,
282                          siginfo_t *__restrict __info,
283                          __const struct timespec *__restrict __timeout);
284
285 /* Send signal SIG to the process PID.  Associate data in VAL with the
286    signal.  */
287 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
288      __THROW;
289 # endif /* Use POSIX 199306.  */
290
291 #endif /* Use POSIX.  */
292
293 #ifdef __USE_BSD
294
295 /* Names of the signals.  This variable exists only for compatibility.
296    Use `strsignal' instead (see <string.h>).  */
297 extern __const char *__const _sys_siglist[_NSIG];
298 extern __const char *__const sys_siglist[_NSIG];
299
300 /* Structure passed to `sigvec'.  */
301 struct sigvec
302   {
303     __sighandler_t sv_handler;  /* Signal handler.  */
304     int sv_mask;                /* Mask of signals to be blocked.  */
305
306     int sv_flags;               /* Flags (see below).  */
307 # define sv_onstack     sv_flags /* 4.2 BSD compatibility.  */
308   };
309
310 /* Bits in `sv_flags'.  */
311 # define SV_ONSTACK     (1 << 0)/* Take the signal on the signal stack.  */
312 # define SV_INTERRUPT   (1 << 1)/* Do not restart system calls.  */
313 # define SV_RESETHAND   (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
314
315
316 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
317    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
318    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
319    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
320    it is filled in with the old information for SIG.  */
321 extern int sigvec (int __sig, __const struct sigvec *__vec,
322                    struct sigvec *__ovec) __THROW;
323
324
325 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
326 # include <bits/sigcontext.h>
327
328 /* Restore the state saved in SCP.  */
329 extern int sigreturn (struct sigcontext *__scp) __THROW;
330
331 #endif /*  use BSD.  */
332
333
334 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
335
336 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
337    (causing them to fail with EINTR); if INTERRUPT is zero, make system
338    calls be restarted after signal SIG.  */
339 extern int siginterrupt (int __sig, int __interrupt) __THROW;
340
341 # include <bits/sigstack.h>
342 # ifdef __USE_XOPEN
343 /* This will define `ucontext_t' and `mcontext_t'.  */
344 #  include <sys/ucontext.h>
345 # endif
346
347 /* Run signals handlers on the stack specified by SS (if not NULL).
348    If OSS is not NULL, it is filled in with the old signal stack status.
349    This interface is obsolete and on many platform not implemented.  */
350 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __THROW;
351
352 /* Alternate signal handler stack interface.
353    This interface should always be preferred over `sigstack'.  */
354 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
355                         struct sigaltstack *__restrict __oss) __THROW;
356
357 #endif /* use BSD or X/Open Unix.  */
358
359 #ifdef __USE_UNIX98
360 /* Simplified interface for signal management.  */
361
362 /* Add SIG to the calling process' signal mask.  */
363 extern int sighold (int __sig) __THROW;
364
365 /* Remove SIG from the calling process' signal mask.  */
366 extern int sigrelse (int __sig) __THROW;
367
368 /* Set the disposition of SIG to SIG_IGN.  */
369 extern int sigignore (int __sig) __THROW;
370
371 /* Set the disposition of SIG.  */
372 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
373 #endif
374
375 #if defined __USE_POSIX199506 || defined __USE_UNIX98
376 /* Some of the functions for handling signals in threaded programs must
377    be defined here.  */
378 # include <bits/pthreadtypes.h>
379 # include <bits/sigthread.h>
380 #endif /* use Unix98 */
381
382 /* The following functions are used internally in the C library and in
383    other code which need deep insights.  */
384
385 /* Return number of available real-time signal with highest priority.  */
386 extern int __libc_current_sigrtmin (void) __THROW;
387 /* Return number of available real-time signal with lowest priority.  */
388 extern int __libc_current_sigrtmax (void) __THROW;
389
390 #endif /* signal.h  */
391
392 __END_DECLS
393
394 #endif /* not signal.h */