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