1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2010 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@
22 #if defined __need_sig_atomic_t || defined __need_sigset_t
23 /* Special invocation convention inside glibc header files. */
25 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
28 /* Normal invocation convention. */
32 /* The include_next requires a split double-inclusion guard. */
33 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
38 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
40 /* The definition of _GL_ARG_NONNULL is copied here. */
42 /* The definition of _GL_WARN_ON_USE is copied here. */
44 /* Define pid_t, uid_t.
45 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
46 #include <sys/types.h>
48 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
49 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
50 Hence, redefine this to a non-volatile type as needed. */
51 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
52 typedef int rpl_sig_atomic_t;
54 # define sig_atomic_t rpl_sig_atomic_t
57 /* A set or mask of signals. */
59 typedef unsigned int sigset_t;
63 #if @GNULIB_SIGNAL_H_SIGPIPE@
65 /* Define SIGPIPE to a value that does not overlap with other signals. */
67 # define GNULIB_defined_SIGPIPE 1
68 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
74 #if @GNULIB_SIGPROCMASK@
75 # if !@HAVE_POSIX_SIGNALBLOCKING@
77 /* Maximum signal number + 1. */
82 /* This code supports only 32 signals. */
83 typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
87 /* Test whether a given signal is contained in a signal set. */
88 # if !@HAVE_POSIX_SIGNALBLOCKING@
89 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
90 _GL_ARG_NONNULL ((1)));
92 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
93 _GL_CXXALIASWARN (sigismember);
95 /* Initialize a signal set to the empty set. */
96 # if !@HAVE_POSIX_SIGNALBLOCKING@
97 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
99 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
100 _GL_CXXALIASWARN (sigemptyset);
102 /* Add a signal to a signal set. */
103 # if !@HAVE_POSIX_SIGNALBLOCKING@
104 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
105 _GL_ARG_NONNULL ((1)));
107 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
108 _GL_CXXALIASWARN (sigaddset);
110 /* Remove a signal from a signal set. */
111 # if !@HAVE_POSIX_SIGNALBLOCKING@
112 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
113 _GL_ARG_NONNULL ((1)));
115 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
116 _GL_CXXALIASWARN (sigdelset);
118 /* Fill a signal set with all possible signals. */
119 # if !@HAVE_POSIX_SIGNALBLOCKING@
120 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
122 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
123 _GL_CXXALIASWARN (sigfillset);
125 /* Return the set of those blocked signals that are pending. */
126 # if !@HAVE_POSIX_SIGNALBLOCKING@
127 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
129 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
130 _GL_CXXALIASWARN (sigpending);
132 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
133 Then, if SET is not NULL, affect the current set of blocked signals by
134 combining it with *SET as indicated in OPERATION.
135 In this implementation, you are not allowed to change a signal handler
136 while the signal is blocked. */
137 # if !@HAVE_POSIX_SIGNALBLOCKING@
138 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
139 # define SIG_SETMASK 1 /* blocked_set = *set; */
140 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
141 _GL_FUNCDECL_SYS (sigprocmask, int,
142 (int operation, const sigset_t *set, sigset_t *old_set));
144 _GL_CXXALIAS_SYS (sigprocmask, int,
145 (int operation, const sigset_t *set, sigset_t *old_set));
146 _GL_CXXALIASWARN (sigprocmask);
148 /* Install the handler FUNC for signal SIG, and return the previous
153 typedef void (*_gl_function_taking_int_returning_void_t) (int);
157 # if !@HAVE_POSIX_SIGNALBLOCKING@
158 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
159 # define signal rpl_signal
161 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
162 (int sig, _gl_function_taking_int_returning_void_t func));
163 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
164 (int sig, _gl_function_taking_int_returning_void_t func));
166 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
167 (int sig, _gl_function_taking_int_returning_void_t func));
169 _GL_CXXALIASWARN (signal);
171 /* Raise signal SIG. */
172 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
173 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
175 # define raise rpl_raise
177 _GL_FUNCDECL_RPL (raise, int, (int sig));
178 _GL_CXXALIAS_RPL (raise, int, (int sig));
180 _GL_CXXALIAS_SYS (raise, int, (int sig));
182 _GL_CXXALIASWARN (raise);
184 #elif defined GNULIB_POSIXCHECK
186 # if HAVE_RAW_DECL_SIGADDSET
187 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
188 "use the gnulib module sigprocmask for portability");
191 # if HAVE_RAW_DECL_SIGDELSET
192 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
193 "use the gnulib module sigprocmask for portability");
196 # if HAVE_RAW_DECL_SIGEMPTYSET
197 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
198 "use the gnulib module sigprocmask for portability");
201 # if HAVE_RAW_DECL_SIGFILLSET
202 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
203 "use the gnulib module sigprocmask for portability");
206 # if HAVE_RAW_DECL_SIGISMEMBER
207 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
208 "use the gnulib module sigprocmask for portability");
211 # if HAVE_RAW_DECL_SIGPENDING
212 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
213 "use the gnulib module sigprocmask for portability");
216 # if HAVE_RAW_DECL_SIGPROCMASK
217 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
218 "use the gnulib module sigprocmask for portability");
220 #endif /* @GNULIB_SIGPROCMASK@ */
223 #if @GNULIB_SIGACTION@
224 # if !@HAVE_SIGACTION@
226 # if !@HAVE_SIGINFO_T@
227 /* Present to allow compilation, but unsupported by gnulib. */
234 /* Present to allow compilation, but unsupported by gnulib. */
245 union sigval si_value;
247 typedef struct siginfo_t siginfo_t;
248 # endif /* !@HAVE_SIGINFO_T@ */
250 /* We assume that platforms which lack the sigaction() function also lack
251 the 'struct sigaction' type, and vice versa. */
257 void (*_sa_handler) (int);
258 /* Present to allow compilation, but unsupported by gnulib. POSIX
259 says that implementations may, but not must, make sa_sigaction
260 overlap with sa_handler, but we know of no implementation where
261 they do not overlap. */
262 void (*_sa_sigaction) (int, siginfo_t *, void *);
265 /* Not all POSIX flags are supported. */
268 # define sa_handler _sa_func._sa_handler
269 # define sa_sigaction _sa_func._sa_sigaction
270 /* Unsupported flags are not present. */
271 # define SA_RESETHAND 1
272 # define SA_NODEFER 2
273 # define SA_RESTART 4
275 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
276 struct sigaction *restrict));
278 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
280 # define sa_sigaction sa_handler
282 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
284 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
285 struct sigaction *restrict));
286 _GL_CXXALIASWARN (sigaction);
288 #elif defined GNULIB_POSIXCHECK
290 # if HAVE_RAW_DECL_SIGACTION
291 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
292 "use the gnulib module sigaction for portability");
296 /* Some systems don't have SA_NODEFER. */
298 # define SA_NODEFER 0
302 #endif /* _GL_SIGNAL_H */
303 #endif /* _GL_SIGNAL_H */