1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2011 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
24 /* Special invocation convention:
25 - Inside glibc header files.
26 - On glibc systems we have a sequence of nested includes
27 <signal.h> -> <ucontext.h> -> <signal.h>.
28 In this situation, the functions are not yet declared, therefore we cannot
29 provide the C++ aliases.
30 - On glibc systems with GCC 4.3 we have a sequence of nested includes
31 <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
32 In this situation, some of the functions are not yet declared, therefore
33 we cannot provide the C++ aliases. */
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
38 /* Normal invocation convention. */
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
42 #define _GL_ALREADY_INCLUDING_SIGNAL_H
44 /* Define pid_t, uid_t.
45 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
46 On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
47 us; so include <sys/types.h> now, before the second inclusion guard. */
48 #include <sys/types.h>
50 /* The include_next requires a split double-inclusion guard. */
51 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
53 #undef _GL_ALREADY_INCLUDING_SIGNAL_H
55 #ifndef _@GUARD_PREFIX@_SIGNAL_H
56 #define _@GUARD_PREFIX@_SIGNAL_H
58 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
60 /* The definition of _GL_ARG_NONNULL is copied here. */
62 /* The definition of _GL_WARN_ON_USE is copied here. */
64 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
65 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
66 Hence, redefine this to a non-volatile type as needed. */
67 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
68 # if !GNULIB_defined_sig_atomic_t
69 typedef int rpl_sig_atomic_t;
71 # define sig_atomic_t rpl_sig_atomic_t
72 # define GNULIB_defined_sig_atomic_t 1
76 /* A set or mask of signals. */
78 # if !GNULIB_defined_sigset_t
79 typedef unsigned int sigset_t;
80 # define GNULIB_defined_sigset_t 1
84 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
85 #if !@HAVE_SIGHANDLER_T@
89 # if !GNULIB_defined_sighandler_t
90 typedef void (*sighandler_t) (int);
91 # define GNULIB_defined_sighandler_t 1
99 #if @GNULIB_SIGNAL_H_SIGPIPE@
101 /* Define SIGPIPE to a value that does not overlap with other signals. */
103 # define GNULIB_defined_SIGPIPE 1
104 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
110 /* Maximum signal number + 1. */
112 # if defined __TANDEM
118 #if @GNULIB_PTHREAD_SIGMASK@
119 # if !@HAVE_PTHREAD_SIGMASK@
120 _GL_FUNCDECL_SYS (pthread_sigmask, int,
121 (int how, const sigset_t *new_mask, sigset_t *old_mask));
123 _GL_CXXALIAS_SYS (pthread_sigmask, int,
124 (int how, const sigset_t *new_mask, sigset_t *old_mask));
125 _GL_CXXALIASWARN (pthread_sigmask);
126 #elif defined GNULIB_POSIXCHECK
127 # undef pthread_sigmask
128 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
129 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
130 "use gnulib module pthread_sigmask for portability");
135 #if @GNULIB_SIGPROCMASK@
136 # if !@HAVE_POSIX_SIGNALBLOCKING@
138 /* Maximum signal number + 1. */
143 /* This code supports only 32 signals. */
144 # if !GNULIB_defined_verify_NSIG_constraint
145 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
146 # define GNULIB_defined_verify_NSIG_constraint 1
151 /* Test whether a given signal is contained in a signal set. */
152 # if @HAVE_POSIX_SIGNALBLOCKING@
153 /* This function is defined as a macro on MacOS X. */
154 # if defined __cplusplus && defined GNULIB_NAMESPACE
158 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
159 _GL_ARG_NONNULL ((1)));
161 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
162 _GL_CXXALIASWARN (sigismember);
164 /* Initialize a signal set to the empty set. */
165 # if @HAVE_POSIX_SIGNALBLOCKING@
166 /* This function is defined as a macro on MacOS X. */
167 # if defined __cplusplus && defined GNULIB_NAMESPACE
171 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
173 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
174 _GL_CXXALIASWARN (sigemptyset);
176 /* Add a signal to a signal set. */
177 # if @HAVE_POSIX_SIGNALBLOCKING@
178 /* This function is defined as a macro on MacOS X. */
179 # if defined __cplusplus && defined GNULIB_NAMESPACE
183 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
184 _GL_ARG_NONNULL ((1)));
186 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
187 _GL_CXXALIASWARN (sigaddset);
189 /* Remove a signal from a signal set. */
190 # if @HAVE_POSIX_SIGNALBLOCKING@
191 /* This function is defined as a macro on MacOS X. */
192 # if defined __cplusplus && defined GNULIB_NAMESPACE
196 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
197 _GL_ARG_NONNULL ((1)));
199 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
200 _GL_CXXALIASWARN (sigdelset);
202 /* Fill a signal set with all possible signals. */
203 # if @HAVE_POSIX_SIGNALBLOCKING@
204 /* This function is defined as a macro on MacOS X. */
205 # if defined __cplusplus && defined GNULIB_NAMESPACE
209 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
211 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
212 _GL_CXXALIASWARN (sigfillset);
214 /* Return the set of those blocked signals that are pending. */
215 # if !@HAVE_POSIX_SIGNALBLOCKING@
216 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
218 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
219 _GL_CXXALIASWARN (sigpending);
221 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
222 Then, if SET is not NULL, affect the current set of blocked signals by
223 combining it with *SET as indicated in OPERATION.
224 In this implementation, you are not allowed to change a signal handler
225 while the signal is blocked. */
226 # if !@HAVE_POSIX_SIGNALBLOCKING@
227 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
228 # define SIG_SETMASK 1 /* blocked_set = *set; */
229 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
230 _GL_FUNCDECL_SYS (sigprocmask, int,
231 (int operation, const sigset_t *set, sigset_t *old_set));
233 _GL_CXXALIAS_SYS (sigprocmask, int,
234 (int operation, const sigset_t *set, sigset_t *old_set));
235 _GL_CXXALIASWARN (sigprocmask);
237 /* Install the handler FUNC for signal SIG, and return the previous
242 # if !GNULIB_defined_function_taking_int_returning_void_t
243 typedef void (*_gl_function_taking_int_returning_void_t) (int);
244 # define GNULIB_defined_function_taking_int_returning_void_t 1
249 # if !@HAVE_POSIX_SIGNALBLOCKING@
250 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
251 # define signal rpl_signal
253 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
254 (int sig, _gl_function_taking_int_returning_void_t func));
255 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
256 (int sig, _gl_function_taking_int_returning_void_t func));
258 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
259 (int sig, _gl_function_taking_int_returning_void_t func));
261 _GL_CXXALIASWARN (signal);
263 /* Raise signal SIG. */
264 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
265 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
267 # define raise rpl_raise
269 _GL_FUNCDECL_RPL (raise, int, (int sig));
270 _GL_CXXALIAS_RPL (raise, int, (int sig));
272 _GL_CXXALIAS_SYS (raise, int, (int sig));
274 _GL_CXXALIASWARN (raise);
276 #elif defined GNULIB_POSIXCHECK
278 # if HAVE_RAW_DECL_SIGADDSET
279 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
280 "use the gnulib module sigprocmask for portability");
283 # if HAVE_RAW_DECL_SIGDELSET
284 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
285 "use the gnulib module sigprocmask for portability");
288 # if HAVE_RAW_DECL_SIGEMPTYSET
289 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
290 "use the gnulib module sigprocmask for portability");
293 # if HAVE_RAW_DECL_SIGFILLSET
294 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
295 "use the gnulib module sigprocmask for portability");
298 # if HAVE_RAW_DECL_SIGISMEMBER
299 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
300 "use the gnulib module sigprocmask for portability");
303 # if HAVE_RAW_DECL_SIGPENDING
304 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
305 "use the gnulib module sigprocmask for portability");
308 # if HAVE_RAW_DECL_SIGPROCMASK
309 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
310 "use the gnulib module sigprocmask for portability");
312 #endif /* @GNULIB_SIGPROCMASK@ */
315 #if @GNULIB_SIGACTION@
316 # if !@HAVE_SIGACTION@
318 # if !@HAVE_SIGINFO_T@
320 # if !GNULIB_defined_siginfo_types
322 /* Present to allow compilation, but unsupported by gnulib. */
329 /* Present to allow compilation, but unsupported by gnulib. */
340 union sigval si_value;
342 typedef struct siginfo_t siginfo_t;
344 # define GNULIB_defined_siginfo_types 1
347 # endif /* !@HAVE_SIGINFO_T@ */
349 /* We assume that platforms which lack the sigaction() function also lack
350 the 'struct sigaction' type, and vice versa. */
352 # if !GNULIB_defined_struct_sigaction
358 void (*_sa_handler) (int);
359 /* Present to allow compilation, but unsupported by gnulib. POSIX
360 says that implementations may, but not must, make sa_sigaction
361 overlap with sa_handler, but we know of no implementation where
362 they do not overlap. */
363 void (*_sa_sigaction) (int, siginfo_t *, void *);
366 /* Not all POSIX flags are supported. */
369 # define sa_handler _sa_func._sa_handler
370 # define sa_sigaction _sa_func._sa_sigaction
371 /* Unsupported flags are not present. */
372 # define SA_RESETHAND 1
373 # define SA_NODEFER 2
374 # define SA_RESTART 4
376 # define GNULIB_defined_struct_sigaction 1
379 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
380 struct sigaction *restrict));
382 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
384 # define sa_sigaction sa_handler
386 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
388 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
389 struct sigaction *restrict));
390 _GL_CXXALIASWARN (sigaction);
392 #elif defined GNULIB_POSIXCHECK
394 # if HAVE_RAW_DECL_SIGACTION
395 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
396 "use the gnulib module sigaction for portability");
400 /* Some systems don't have SA_NODEFER. */
402 # define SA_NODEFER 0
406 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
407 #endif /* _@GUARD_PREFIX@_SIGNAL_H */