OSDN Git Service

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