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