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      1
27 # include <features.h>
28 #endif
29
30 __BEGIN_DECLS
31
32 #include <bits/types.h>
33 #include <bits/sigset.h>                /* __sigset_t, __sig_atomic_t.  */
34
35 #if defined _SIGNAL_H && defined __USE_UNIX98 && !defined pid_t
36 typedef __pid_t pid_t;
37 # define pid_t pid_t
38 #endif  /* Unix98 */
39
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
48
49 #ifdef _SIGNAL_H
50
51 #include <bits/signum.h>
52
53 /* Type of a signal handler.  */
54 typedef void (*__sighandler_t) __P ((int));
55
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
62 /* Set the handler for the signal SIG to HANDLER, returning the old
63    handler, or SIG_ERR on error.
64    By default `signal' has the BSD semantic.  */
65 #ifdef __USE_BSD
66 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
67 #else
68 /* Make sure the used `signal' implementation is the SVID version.
69    When GNU CC is used we have a clean way to write this.  */
70 # if defined __GNUC__ && __GNUC__ >= 2
71 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler))
72      __asm__ ("__sysv_signal");
73 # else
74 #  define signal(sig, handler) __sysv_signal ((sig), (handler))
75 # endif
76 #endif
77
78 #ifdef __USE_XOPEN
79 /* The X/Open definition of `signal' conflicts with the BSD version.
80    So they defined another function `bsd_signal'.  */
81 extern __sighandler_t __bsd_signal __P ((int __sig, __sighandler_t __handler));
82 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
83 #endif
84
85 /* Send signal SIG to process number PID.  If PID is zero,
86    send SIG to all processes in the current process's process group.
87    If PID is < -1, send SIG to all processes in process group - PID.  */
88 extern int __kill __P ((__pid_t __pid, int __sig));
89 #ifdef __USE_POSIX
90 extern int kill __P ((__pid_t __pid, int __sig));
91 #endif /* Use POSIX.  */
92
93 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
94 /* Send SIG to all processes in process group PGRP.
95    If PGRP is zero, send SIG to all processes in
96    the current process's process group.  */
97 extern int killpg __P ((__pid_t __pgrp, int __sig));
98 #endif /* Use BSD || X/Open Unix.  */
99
100 /* Raise signal SIG, i.e., send SIG to yourself.  */
101 extern int raise __P ((int __sig));
102
103 #ifdef __USE_SVID
104 /* SVID names for the same things.  */
105 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
106 extern int gsignal __P ((int __sig));
107 #endif /* Use SVID.  */
108
109 #ifdef __USE_MISC
110 /* Print a message describing the meaning of the given signal number.  */
111 extern void psignal __P ((int __sig, __const char *__s));
112 #endif /* Use misc.  */
113
114
115 /* Block signals in MASK, returning the old mask.  */
116 extern int __sigblock __P ((int __mask));
117
118 /* Set the mask of blocked signals to MASK, returning the old mask.  */
119 extern int __sigsetmask __P ((int __mask));
120
121
122 /* The `sigpause' function has two different interfaces.  The original
123    BSD definition defines the argument as a mask of the signal, while
124    the more modern interface in X/Open defines it as the signal
125    number.  We go with the BSD version unless the user explicitly
126    selects the X/Open version.  */
127 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
128
129 #if defined __USE_BSD || defined __USE_GNU
130 /* Set the mask of blocked signals to MASK,
131    wait for a signal to arrive, and then restore the mask.  */
132 extern int sigpause __P ((int __mask));
133 # define sigpause(mask) __sigpause ((mask), 0)
134 #else
135 # ifdef __USE_XOPEN
136 /* Remove a signal from the signal mask and suspend the process.  */
137 #  define sigpause(sig) __sigpause ((sig), 1)
138 # endif
139 #endif
140
141
142 #ifdef __USE_BSD
143 # define sigmask(sig)   __sigmask(sig)
144
145 extern int sigblock __P ((int __mask));
146 extern int sigsetmask __P ((int __mask));
147
148 /* This function is here only for compatibility.
149    Use `sigprocmask' instead.  */
150 extern int siggetmask __P ((void));
151 #endif /* Use BSD.  */
152
153
154 #ifdef __USE_MISC
155 # define NSIG   _NSIG
156 #endif
157
158 #ifdef __USE_GNU
159 typedef __sighandler_t sighandler_t;
160 #endif
161
162 /* 4.4 BSD uses the name `sig_t' for this.  */
163 #ifdef __USE_BSD
164 typedef __sighandler_t sig_t;
165 #endif
166
167 #endif /* <signal.h> included.  */
168
169
170 #ifdef __USE_POSIX
171
172 # if !defined __sigset_t_defined \
173     && (defined _SIGNAL_H  || defined __need_sigset_t)
174 typedef __sigset_t sigset_t;
175 #  define __sigset_t_defined    1
176 # endif /* `sigset_t' not defined and <signal.h> or need `sigset_t'.  */
177 # undef __need_sigset_t
178
179 # ifdef _SIGNAL_H
180
181 /* We need `struct timespec' later on.  */
182 #  define __need_timespec
183 #  include <time.h>
184
185 /* Get the `siginfo_t' type plus the needed symbols.  */
186 #  include <bits/siginfo.h>
187
188 /* Clear all signals from SET.  */
189 extern int sigemptyset __P ((sigset_t *__set));
190
191 /* Set all signals in SET.  */
192 extern int sigfillset __P ((sigset_t *__set));
193
194 /* Add SIGNO to SET.  */
195 extern int sigaddset __P ((sigset_t *__set, int __signo));
196
197 /* Remove SIGNO from SET.  */
198 extern int sigdelset __P ((sigset_t *__set, int __signo));
199
200 /* Return 1 if SIGNO is in SET, 0 if not.  */
201 extern int sigismember __P ((__const sigset_t *__set, int __signo));
202
203 #  ifdef __USE_GNU
204 /* Return non-empty value is SET is not empty.  */
205 extern int sigisemptyset __P ((__const sigset_t *__set));
206
207 /* Build new signal set by combining the two inputs set using logical AND.  */
208 extern int sigandset __P ((sigset_t *__set, __const sigset_t *__left,
209                            __const sigset_t *__right));
210
211 /* Build new signal set by combining the two inputs set using logical OR.  */
212 extern int sigorset __P ((sigset_t *__set, __const sigset_t *__left,
213                           __const sigset_t *__right));
214 #  endif /* GNU */
215
216 /* Get the system-specific definitions of `struct sigaction'
217    and the `SA_*' and `SIG_*'. constants.  */
218 #  include <bits/sigaction.h>
219
220 /* Get and/or change the set of blocked signals.  */
221 extern int __sigprocmask __P ((int __how,
222                                __const sigset_t *__set, sigset_t *__oset));
223 extern int sigprocmask __P ((int __how,
224                              __const sigset_t *__set, sigset_t *__oset));
225
226 /* Change the set of blocked signals to SET,
227    wait until a signal arrives, and restore the set of blocked signals.  */
228 extern int __sigsuspend __P ((__const sigset_t *__set));
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 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
244
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 extern int sigwaitinfo __P ((__const sigset_t *__set, siginfo_t *__info));
248
249 /* Select any of pending signals from SET and place information in INFO.
250    Wait the imte specified by TIMEOUT if no signal is pending.  */
251 extern int __sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
252                                 __const struct timespec *__timeout));
253 extern int sigtimedwait __P ((__const sigset_t *__set, siginfo_t *__info,
254                               __const struct timespec *__timeout));
255
256 /* Send signal SIG to the process PID.  Associate data in VAL with the
257    signal.  */
258 extern int __sigqueue __P ((__pid_t __pid, int __sig,
259                             __const union sigval __val));
260 extern int sigqueue __P ((__pid_t __pid, int __sig,
261                           __const union sigval __val));
262
263 # endif /* <signal.h> included.  */
264
265 #endif /* Use POSIX.  */
266
267 #if defined _SIGNAL_H && defined __USE_BSD
268
269 /* Names of the signals.  This variable exists only for compatibility.
270    Use `strsignal' instead (see <string.h>).  */
271 extern __const char *__const _sys_siglist[_NSIG];
272 extern __const char *__const sys_siglist[_NSIG];
273
274 /* Structure passed to `sigvec'.  */
275 struct sigvec
276   {
277     __sighandler_t sv_handler;  /* Signal handler.  */
278     int sv_mask;                /* Mask of signals to be blocked.  */
279
280     int sv_flags;               /* Flags (see below).  */
281 # define sv_onstack     sv_flags /* 4.2 BSD compatibility.  */
282   };
283
284 /* Bits in `sv_flags'.  */
285 # define SV_ONSTACK     (1 << 0)/* Take the signal on the signal stack.  */
286 # define SV_INTERRUPT   (1 << 1)/* Do not restart system calls.  */
287 # define SV_RESETHAND   (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
288
289
290 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
291    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
292    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
293    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
294    it is filled in with the old information for SIG.  */
295 extern int __sigvec __P ((int __sig, __const struct sigvec *__vec,
296                           struct sigvec *__ovec));
297 extern int sigvec __P ((int __sig, __const struct sigvec *__vec,
298                         struct sigvec *__ovec));
299
300
301 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
302 # include <bits/sigcontext.h>
303
304 /* Restore the state saved in SCP.  */
305 extern int __sigreturn __P ((struct sigcontext *__scp));
306 extern int sigreturn __P ((struct sigcontext *__scp));
307
308 #endif /* signal.h included and use BSD.  */
309
310
311 #if defined _SIGNAL_H && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
312
313 # define __need_size_t
314 # include <stddef.h>
315
316 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
317    (causing them to fail with EINTR); if INTERRUPT is zero, make system
318    calls be restarted after signal SIG.  */
319 extern int siginterrupt __P ((int __sig, int __interrupt));
320
321
322 /* Structure describing a signal stack.  */
323 struct sigstack
324   {
325     __ptr_t ss_sp;              /* Signal stack pointer.  */
326     int ss_onstack;             /* Nonzero if executing on this stack.  */
327   };
328
329 /* Run signals handlers on the stack specified by SS (if not NULL).
330    If OSS is not NULL, it is filled in with the old signal stack status.  */
331 extern int sigstack __P ((__const struct sigstack *__ss,
332                           struct sigstack *__oss));
333
334 /* Alternate interface.  */
335 typedef struct sigaltstack
336   {
337     __ptr_t ss_sp;
338     size_t ss_size;
339     int ss_flags;
340   } stack_t;
341
342 extern int sigaltstack __P ((__const struct sigaltstack *__ss,
343                              struct sigaltstack *__oss));
344
345 #endif /* signal.h included and use BSD or X/Open Unix.  */
346
347
348 #if defined _SIGNAL_H && defined __USE_UNIX98
349 /* Simplified interface for signal management.  */
350
351 /* Add SIG to the calling process' signal mask.  */
352 extern int sighold __P ((int __sig));
353
354 /* Remove SIG from the calling process' signal mask.  */
355 extern int sigrelse __P ((int __sig));
356
357 /* Set the disposition of SIG to SIG_IGN.  */
358 extern int sigignore __P ((int __sig));
359
360 /* Set the disposition of SIG.  */
361 extern __sighandler_t sigset __P ((int __sig, __sighandler_t __disp));
362 #endif
363
364
365 /* The following functions are used internally in the C library and in
366    other code which need deep insights.  */
367
368 /* Return number of available real-time signal with highest priority.  */
369 extern int __libc_current_sigrtmin __P ((void));
370 /* Return number of available real-time signal with lowest priority.  */
371 extern int __libc_current_sigrtmax __P ((void));
372
373 /* Allocate real-time signal with highest/lowest available priority.  */
374 extern int __libc_allocate_rtsig __P ((int __high));
375
376 __END_DECLS
377
378 #endif /* signal.h  */