Clang Project

include/signal.h
1/* Copyright (C) 1991-2016 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
25define _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
37ifndef __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
42endif
43# undef __need_sig_atomic_t
44#endif
45
46#if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
47ifndef __sigset_t_defined
48#  define __sigset_t_defined
49typedef __sigset_t sigset_t;
50endif
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
60ifndef __pid_t_defined
61typedef __pid_t pid_t;
62#  define __pid_t_defined
63#endif
64#ifdef __USE_XOPEN
65endif
66ifndef __uid_t_defined
67typedef __uid_t uid_t;
68#  define __uid_t_defined
69endif
70#endif /* Unix98 */
71
72#ifdef __USE_POSIX199309
73/* We need `struct timespec' later on.  */
74define __need_timespec
75include <time.h>
76#endif
77
78#if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
79/* Get the `siginfo_t' type plus the needed symbols.  */
80include <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_MISC
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 __pidint __sig__THROW;
128#endif /* Use POSIX.  */
129
130#if defined __USE_MISC || 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 __pgrpint __sig__THROW;
135#endif /* Use misc || 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_MISC
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 misc.  */
148
149#ifdef __USE_XOPEN2K8
150/* Print a message describing the meaning of the given signal number.  */
151extern void psignal (int __sigconst char *__s);
152
153/* Print a message describing the meaning of the given signal information.  */
154extern void psiginfo (const siginfo_t *__pinfoconst char *__s);
155#endif /* POSIX 2008.  */
156
157
158
159/* The `sigpause' function in X/Open defines the argument as the
160   signal number.  This requires redirecting to another function
161   because the default version in glibc uses an old BSD interface.
162
163   This function is a cancellation point and therefore not marked with
164   __THROW.  */
165
166#ifdef __USE_XOPEN
167ifdef __GNUC__
168extern int sigpause (int __sig__asm__ ("__xpg_sigpause");
169else
170extern int __sigpause (int __sig_or_mask, int __is_sig);
171/* Remove a signal from the signal mask and suspend the process.  */
172#  define sigpause(sig) __sigpause ((sig), 1)
173endif
174#endif
175
176
177#ifdef __USE_MISC
178/* None of the following functions should be used anymore.  They are here
179   only for compatibility.  A single word (`int') is not guaranteed to be
180   enough to hold a complete signal mask and therefore these functions
181   simply do not work in many situations.  Use `sigprocmask' instead.  */
182
183/* Compute mask for signal SIG.  */
184define sigmask(sig) __sigmask(sig)
185
186/* Block signals in MASK, returning the old mask.  */
187extern int sigblock (int __mask__THROW __attribute_deprecated__;
188
189/* Set the mask of blocked signals to MASK, returning the old mask.  */
190extern int sigsetmask (int __mask__THROW __attribute_deprecated__;
191
192/* Return currently selected signal mask.  */
193extern int siggetmask (void__THROW __attribute_deprecated__;
194#endif /* Use misc.  */
195
196
197#ifdef __USE_MISC
198define NSIG _NSIG
199#endif
200
201#ifdef __USE_GNU
202typedef __sighandler_t sighandler_t;
203#endif
204
205/* 4.4 BSD uses the name `sig_t' for this.  */
206#ifdef __USE_MISC
207typedef __sighandler_t sig_t;
208#endif
209
210#ifdef __USE_POSIX
211
212/* Clear all signals from SET.  */
213extern int sigemptyset (sigset_t *__set__THROW __nonnull ((1));
214
215/* Set all signals in SET.  */
216extern int sigfillset (sigset_t *__set__THROW __nonnull ((1));
217
218/* Add SIGNO to SET.  */
219extern int sigaddset (sigset_t *__setint __signo__THROW __nonnull ((1));
220
221/* Remove SIGNO from SET.  */
222extern int sigdelset (sigset_t *__setint __signo__THROW __nonnull ((1));
223
224/* Return 1 if SIGNO is in SET, 0 if not.  */
225extern int sigismember (const sigset_t *__setint __signo)
226     __THROW __nonnull ((1));
227
228ifdef __USE_GNU
229/* Return non-empty value is SET is not empty.  */
230extern int sigisemptyset (const sigset_t *__set__THROW __nonnull ((1));
231
232/* Build new signal set by combining the two inputs set using logical AND.  */
233extern int sigandset (sigset_t *__setconst sigset_t *__left,
234       const sigset_t *__right__THROW __nonnull ((123));
235
236/* Build new signal set by combining the two inputs set using logical OR.  */
237extern int sigorset (sigset_t *__setconst sigset_t *__left,
238      const sigset_t *__right__THROW __nonnull ((123));
239endif /* GNU */
240
241/* Get the system-specific definitions of `struct sigaction'
242   and the `SA_*' and `SIG_*'. constants.  */
243include <bits/sigaction.h>
244
245/* Get and/or change the set of blocked signals.  */
246extern int sigprocmask (int __howconst sigset_t *__restrict __set,
247 sigset_t *__restrict __oset__THROW;
248
249/* Change the set of blocked signals to SET,
250   wait until a signal arrives, and restore the set of blocked signals.
251
252   This function is a cancellation point and therefore not marked with
253   __THROW.  */
254extern int sigsuspend (const sigset_t *__set__nonnull ((1));
255
256/* Get and/or set the action for signal SIG.  */
257extern int sigaction (int __sigconst struct sigaction *__restrict __act,
258       struct sigaction *__restrict __oact__THROW;
259
260/* Put in SET all signals that are blocked and waiting to be delivered.  */
261extern int sigpending (sigset_t *__set__THROW __nonnull ((1));
262
263
264/* Select any of pending signals from SET or wait for any to arrive.
265
266   This function is a cancellation point and therefore not marked with
267   __THROW.  */
268extern int sigwait (const sigset_t *__restrict __setint *__restrict __sig)
269     __nonnull ((12));
270
271ifdef __USE_POSIX199309
272/* Select any of pending signals from SET and place information in INFO.
273
274   This function is a cancellation point and therefore not marked with
275   __THROW.  */
276extern int sigwaitinfo (const sigset_t *__restrict __set,
277 siginfo_t *__restrict __info__nonnull ((1));
278
279/* Select any of pending signals from SET and place information in INFO.
280   Wait the time specified by TIMEOUT if no signal is pending.
281
282   This function is a cancellation point and therefore not marked with
283   __THROW.  */
284extern int sigtimedwait (const sigset_t *__restrict __set,
285  siginfo_t *__restrict __info,
286  const struct timespec *__restrict __timeout)
287     __nonnull ((1));
288
289/* Send signal SIG to the process PID.  Associate data in VAL with the
290   signal.  */
291extern int sigqueue (__pid_t __pidint __sigconst union sigval __val)
292     __THROW;
293endif /* Use POSIX 199306.  */
294
295#endif /* Use POSIX.  */
296
297#ifdef __USE_MISC
298
299/* Names of the signals.  This variable exists only for compatibility.
300   Use `strsignal' instead (see <string.h>).  */
301extern const char *const _sys_siglist[_NSIG];
302extern const char *const sys_siglist[_NSIG];
303
304
305/* Get machine-dependent `struct sigcontext' and signal subcodes.  */
306include <bits/sigcontext.h>
307
308/* Restore the state saved in SCP.  */
309extern int sigreturn (struct sigcontext *__scp__THROW;
310
311#endif /* Use misc.  */
312
313
314#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
315define __need_size_t
316include <stddef.h>
317
318/* If INTERRUPT is nonzero, make signal SIG interrupt system calls
319   (causing them to fail with EINTR); if INTERRUPT is zero, make system
320   calls be restarted after signal SIG.  */
321extern int siginterrupt (int __sigint __interrupt__THROW;
322
323include <bits/sigstack.h>
324if defined __USE_XOPEN || defined __USE_XOPEN2K8
325/* This will define `ucontext_t' and `mcontext_t'.  */
326#  include <sys/ucontext.h>
327endif
328
329/* Run signals handlers on the stack specified by SS (if not NULL).
330   If OSS is not NULL, it is filled in with the old signal stack status.
331   This interface is obsolete and on many platform not implemented.  */
332extern int sigstack (struct sigstack *__ssstruct sigstack *__oss)
333     __THROW __attribute_deprecated__;
334
335/* Alternate signal handler stack interface.
336   This interface should always be preferred over `sigstack'.  */
337extern int sigaltstack (const struct sigaltstack *__restrict __ss,
338 struct sigaltstack *__restrict __oss__THROW;
339
340#endif /* Use POSIX.1-2008 or X/Open Unix.  */
341
342#ifdef __USE_XOPEN_EXTENDED
343/* Simplified interface for signal management.  */
344
345/* Add SIG to the calling process' signal mask.  */
346extern int sighold (int __sig__THROW;
347
348/* Remove SIG from the calling process' signal mask.  */
349extern int sigrelse (int __sig__THROW;
350
351/* Set the disposition of SIG to SIG_IGN.  */
352extern int sigignore (int __sig__THROW;
353
354/* Set the disposition of SIG.  */
355extern __sighandler_t sigset (int __sig__sighandler_t __disp__THROW;
356#endif
357
358#if defined __USE_POSIX199506 || defined __USE_UNIX98
359/* Some of the functions for handling signals in threaded programs must
360   be defined here.  */
361include <bits/pthreadtypes.h>
362include <bits/sigthread.h>
363#endif /* use Unix98 */
364
365/* The following functions are used internally in the C library and in
366   other code which need deep insights.  */
367
368/* Return number of available real-time signal with highest priority.  */
369extern int __libc_current_sigrtmin (void__THROW;
370/* Return number of available real-time signal with lowest priority.  */
371extern int __libc_current_sigrtmax (void__THROW;
372
373#endif /* signal.h  */
374
375__END_DECLS
376
377#endif /* not signal.h */
378