update from main archive 961229
[platform/upstream/glibc.git] / signal / signal.h
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96 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 <gnu/types.h>
33 #include <sigset.h>             /* __sigset_t, __sig_atomic_t.  */
34
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
42
43 #ifdef _SIGNAL_H
44
45 #include <signum.h>
46
47 /* Type of a signal handler.  */
48 typedef void (*__sighandler_t) __P ((int));
49
50 /* Set the handler for the signal SIG to HANDLER,
51    returning the old handler, or SIG_ERR on error.  */
52 extern __sighandler_t signal __P ((int __sig, __sighandler_t __handler));
53
54 #if defined __FAVOR_BSD || defined __USE_XOPEN
55 /* The X/Open definition of `signal' conflicts with the BSD version.
56    So they defined another function `bsd_signal'.  We will use this
57    implementation as the official `signal' function if the BSD
58    interface is preferred.  */
59 extern __sighandler_t bsd_signal __P ((int __sig, __sighandler_t __handler));
60
61 #ifdef __FAVOR_BSD
62 #define signal(sig, handler) bsd_signal ((sig), (handler))
63 #endif
64 #endif
65
66 /* Send signal SIG to process number PID.  If PID is zero,
67    send SIG to all processes in the current process's process group.
68    If PID is < -1, send SIG to all processes in process group - PID.  */
69 extern int __kill __P ((__pid_t __pid, int __sig));
70 #ifdef __USE_POSIX
71 extern int kill __P ((__pid_t __pid, int __sig));
72 #endif /* Use POSIX.  */
73
74 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
75 /* Send SIG to all processes in process group PGRP.
76    If PGRP is zero, send SIG to all processes in
77    the current process's process group.  */
78 extern int killpg __P ((__pid_t __pgrp, int __sig));
79 #endif /* Use BSD || X/Open Unix.  */
80
81 /* Raise signal SIG, i.e., send SIG to yourself.  */
82 extern int raise __P ((int __sig));
83
84 #ifdef __USE_SVID
85 /* SVID names for the same things.  */
86 extern __sighandler_t ssignal __P ((int __sig, __sighandler_t __handler));
87 extern int gsignal __P ((int __sig));
88 #endif /* Use SVID.  */
89
90 #ifdef __USE_MISC
91 /* Print a message describing the meaning of the given signal number.  */
92 extern void psignal __P ((int __sig, __const char *__s));
93 #endif /* Use misc.  */
94
95
96 /* Block signals in MASK, returning the old mask.  */
97 extern int __sigblock __P ((int __mask));
98
99 /* Set the mask of blocked signals to MASK, returning the old mask.  */
100 extern int __sigsetmask __P ((int __mask));
101
102
103 /* The `sigpause' function has two different interfaces.  The original
104    BSD definition defines the argument as a mask of the signal, while
105    the more modern interface in X/Open defines it as the signal
106    number.  We go with the more modern version unless the user
107    explitcly selects the BSD version.  */
108 extern int __sigpause __P ((int __sig_or_mask, int __is_sig));
109
110 #if defined __USE_BSD  && !defined __USE_XOPEN
111 /* Set the mask of blocked signals to MASK,
112    wait for a signal to arrive, and then restore the mask.  */
113 #define sigpause(mask) __sigpause ((mask), 0)
114 #else
115 #ifdef __USE_XOPEN
116 /* Remove a signal from the signal mask and suspend the process.  */
117 #define sigpause(sig) __sigpause ((sig), 1)
118 #endif
119 #endif
120
121
122 #ifdef __USE_BSD
123 #define sigmask(sig)    __sigmask(sig)
124
125 extern int sigblock __P ((int __mask));
126 extern int sigsetmask __P ((int __mask));
127
128 /* This function is here only for compatibility.
129    Use `sigprocmask' instead.  */
130 extern int siggetmask __P ((void));
131 #endif /* Use BSD.  */
132
133
134 #ifdef __USE_MISC
135 #define NSIG    _NSIG
136 #endif
137
138 #ifdef __USE_GNU
139 typedef __sighandler_t sighandler_t;
140 #endif
141
142 /* 4.4 BSD uses the name `sig_t' for this.  */
143 #ifdef __USE_BSD
144 typedef __sighandler_t sig_t;
145 #endif
146
147 #endif /* <signal.h> included.  */
148
149
150 #ifdef __USE_POSIX
151
152 #if !defined __sigset_t_defined \
153     && (defined _SIGNAL_H  || defined __need_sigset_t)
154 typedef __sigset_t sigset_t;
155 #define __sigset_t_defined      1
156 #endif /* `sigset_t' not defined and <signal.h> or need `sigset_t'.  */
157 #undef __need_sigset_t
158
159 #ifdef _SIGNAL_H
160
161 /* Clear all signals from SET.  */
162 extern int sigemptyset __P ((sigset_t *__set));
163
164 /* Set all signals in SET.  */
165 extern int sigfillset __P ((sigset_t *__set));
166
167 /* Add SIGNO to SET.  */
168 extern int sigaddset __P ((sigset_t *__set, int __signo));
169
170 /* Remove SIGNO from SET.  */
171 extern int sigdelset __P ((sigset_t *__set, int __signo));
172
173 /* Return 1 if SIGNO is in SET, 0 if not.  */
174 extern int sigismember __P ((__const sigset_t *__set, int __signo));
175
176 /* Get the system-specific definitions of `struct sigaction'
177    and the `SA_*' and `SIG_*'. constants.  */
178 #include <sigaction.h>
179
180 /* Get and/or change the set of blocked signals.  */
181 extern int __sigprocmask __P ((int __how,
182                                __const sigset_t *__set, sigset_t *__oset));
183 extern int sigprocmask __P ((int __how,
184                              __const sigset_t *__set, sigset_t *__oset));
185
186 /* Change the set of blocked signals to SET,
187    wait until a signal arrives, and restore the set of blocked signals.  */
188 extern int __sigsuspend __P ((__const sigset_t *__set));
189 extern int sigsuspend __P ((__const sigset_t *__set));
190
191 /* Get and/or set the action for signal SIG.  */
192 extern int __sigaction __P ((int __sig, __const struct sigaction *__act,
193                              struct sigaction *__oact));
194 extern int sigaction __P ((int __sig, __const struct sigaction *__act,
195                            struct sigaction *__oact));
196
197 /* Put in SET all signals that are blocked and waiting to be delivered.  */
198 extern int sigpending __P ((sigset_t *__set));
199
200
201 /* Select any of pending signals from SET or wait for any to arrive.  */
202 extern int __sigwait __P ((__const sigset_t *__set, int *__sig));
203 extern int sigwait __P ((__const sigset_t *__set, int *__sig));
204
205 #endif /* <signal.h> included.  */
206
207 #endif /* Use POSIX.  */
208
209 #if defined _SIGNAL_H && defined __USE_BSD
210
211 /* Names of the signals.  This variable exists only for compatibility.
212    Use `strsignal' instead (see <string.h>).  */
213 extern __const char *__const _sys_siglist[NSIG];
214 extern __const char *__const sys_siglist[NSIG];
215
216 /* Structure passed to `sigvec'.  */
217 struct sigvec
218   {
219     __sighandler_t sv_handler;  /* Signal handler.  */
220     int sv_mask;                /* Mask of signals to be blocked.  */
221
222     int sv_flags;               /* Flags (see below).  */
223 #define sv_onstack      sv_flags /* 4.2 BSD compatibility.  */
224   };
225
226 /* Bits in `sv_flags'.  */
227 #define SV_ONSTACK      (1 << 0)/* Take the signal on the signal stack.  */
228 #define SV_INTERRUPT    (1 << 1)/* Do not restart system calls.  */
229 #define SV_RESETHAND    (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
230
231
232 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
233    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
234    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
235    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
236    it is filled in with the old information for SIG.  */
237 extern int __sigvec __P ((int __sig, __const struct sigvec *__vec,
238                           struct sigvec *__ovec));
239 extern int sigvec __P ((int __sig, __const struct sigvec *__vec,
240                         struct sigvec *__ovec));
241
242
243 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
244 #include <sigcontext.h>
245
246 /* Restore the state saved in SCP.  */
247 extern int __sigreturn __P ((struct sigcontext *__scp));
248 extern int sigreturn __P ((struct sigcontext *__scp));
249
250 #endif /* signal.h included and use BSD.  */
251
252
253 #if defined _SIGNAL_H && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
254
255 #define  __need_size_t
256 #include <stddef.h>
257
258 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
259    (causing them to fail with EINTR); if INTERRUPT is zero, make system
260    calls be restarted after signal SIG.  */
261 extern int siginterrupt __P ((int __sig, int __interrupt));
262
263
264 /* Structure describing a signal stack.  */
265 struct sigstack
266   {
267     __ptr_t ss_sp;              /* Signal stack pointer.  */
268     int ss_onstack;             /* Nonzero if executing on this stack.  */
269   };
270
271 /* Run signals handlers on the stack specified by SS (if not NULL).
272    If OSS is not NULL, it is filled in with the old signal stack status.  */
273 extern int sigstack __P ((__const struct sigstack *__ss,
274                           struct sigstack *__oss));
275
276 /* Alternate interface.  */
277 struct sigaltstack
278   {
279     __ptr_t ss_sp;
280     size_t ss_size;
281     int ss_flags;
282   };
283
284 extern int sigaltstack __P ((__const struct sigaltstack *__ss,
285                              struct sigaltstack *__oss));
286
287 #endif /* signal.h included and use BSD or X/Open Unix.  */
288
289 __END_DECLS
290
291 #endif /* signal.h  */