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