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