Debian Codegraph @

lib/signal.in.h

raw
1 /* A GNU-like <signal.h>.
2
3 Copyright (C) 2006-2026 Free Software Foundation, Inc.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _@GUARD_PREFIX@_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. */
34
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
36
37 #else
38 /* Normal invocation convention. */
39
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
41
42 #define _@GUARD_PREFIX@_ALREADY_INCLUDING_SIGNAL_H
43
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>
49
50 /* The include_next requires a split double-inclusion guard. */
51 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
52
53 #undef _@GUARD_PREFIX@_ALREADY_INCLUDING_SIGNAL_H
54
55 #ifndef _@GUARD_PREFIX@_SIGNAL_H
56 #define _@GUARD_PREFIX@_SIGNAL_H
57
58 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
59 #if !_GL_CONFIG_H_INCLUDED
60 #error "Please include config.h first."
61 #endif
62
63 /* For testing the OpenBSD version. */
64 #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
65 && defined __OpenBSD__
66 # include <sys/param.h>
67 #endif
68
69 /* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, Solaris 2.6, Android,
70 OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
71 But avoid namespace pollution on glibc systems.*/
72 #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
73 && ((defined __APPLE__ && defined __MACH__) \
74 || (defined __FreeBSD__ && __FreeBSD__ < 8) \
75 || (defined __OpenBSD__ && OpenBSD < 201205) \
76 || defined __sun || defined __ANDROID__ \
77 || defined __KLIBC__) \
78 && ! defined __GLIBC__
79 # include <pthread.h>
80 #endif
81
82 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
83
84 /* The definition of _GL_ARG_NONNULL is copied here. */
85
86 /* The definition of _GL_WARN_ON_USE is copied here. */
87
88 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
89 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
90 Hence, redefine this to a non-volatile type as needed. */
91 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
92 # if !GNULIB_defined_sig_atomic_t
93 typedef int rpl_sig_atomic_t;
94 # undef sig_atomic_t
95 # define sig_atomic_t rpl_sig_atomic_t
96 # define GNULIB_defined_sig_atomic_t 1
97 # endif
98 #endif
99
100 /* A set or mask of signals. */
101 #if !@HAVE_SIGSET_T@
102 # if !GNULIB_defined_sigset_t
103 typedef unsigned int sigset_t;
104 # define GNULIB_defined_sigset_t 1
105 # endif
106 #endif
107
108 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
109 #if !@HAVE_SIGHANDLER_T@
110 # ifdef __cplusplus
111 extern "C" {
112 # endif
113 # if !GNULIB_defined_sighandler_t
114 typedef void (*sighandler_t) (int);
115 # define GNULIB_defined_sighandler_t 1
116 # endif
117 # ifdef __cplusplus
118 }
119 # endif
120 #endif
121
122
123 #if @GNULIB_SIGNAL_H_SIGPIPE@
124 # ifndef SIGPIPE
125 /* Define SIGPIPE to a value that does not overlap with other signals. */
126 # define SIGPIPE 13
127 # define GNULIB_defined_SIGPIPE 1
128 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
129 'write', 'stdio'. */
130 # endif
131 #endif
132
133
134 /* Maximum signal number + 1. */
135 #ifndef NSIG
136 # if defined __TANDEM
137 # define NSIG 32
138 # endif
139 #endif
140
141
142 /* Maximum size of a signal name returned by sig2str(), including the
143 terminating NUL byte. */
144 #ifndef SIG2STR_MAX
145 /* The longest one: "RTMAX", then "+" or "-", then up to 10 digits, then NUL.
146 Add + 2 as a reserve for the future. */
147 # define SIG2STR_MAX (5 + 1 + 10 + 1 + 2)
148 #endif
149
150 #if @GNULIB_SIG2STR@
151 # if !@HAVE_SIG2STR@
152 _GL_FUNCDECL_SYS (sig2str, int, (int signo, char *str), );
153 # endif
154 _GL_CXXALIAS_SYS (sig2str, int, (int signo, char *str));
155 # if __GLIBC__ >= 2
156 _GL_CXXALIASWARN (sig2str);
157 # endif
158 #elif defined GNULIB_POSIXCHECK
159 # if HAVE_RAW_DECL_SIG2STR
160 _GL_WARN_ON_USE (sig2str, "sig2str is not portable - "
161 "use gnulib module sig2str for portability");
162 # endif
163 #endif
164
165 #if @GNULIB_SIG2STR@
166 # if !@HAVE_STR2SIG@
167 _GL_FUNCDECL_SYS (str2sig, int, (char const *str, int *signo_p), );
168 # endif
169 _GL_CXXALIAS_SYS (str2sig, int, (char const *str, int *signo_p));
170 # if __GLIBC__ >= 2
171 _GL_CXXALIASWARN (str2sig);
172 # endif
173 #elif defined GNULIB_POSIXCHECK
174 # if HAVE_RAW_DECL_STR2SIG
175 _GL_WARN_ON_USE (str2sig, "str2sig is not portable - "
176 "use gnulib module sig2str for portability");
177 # endif
178 #endif
179
180
181 #if @GNULIB_PTHREAD_SIGMASK@
182 # if @REPLACE_PTHREAD_SIGMASK@
183 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184 # undef pthread_sigmask
185 # define pthread_sigmask rpl_pthread_sigmask
186 # endif
187 _GL_FUNCDECL_RPL (pthread_sigmask, int,
188 (int how,
189 const sigset_t *restrict new_mask,
190 sigset_t *restrict old_mask), );
191 _GL_CXXALIAS_RPL (pthread_sigmask, int,
192 (int how,
193 const sigset_t *restrict new_mask,
194 sigset_t *restrict old_mask));
195 # else
196 # if !(@HAVE_PTHREAD_SIGMASK@ || defined pthread_sigmask)
197 _GL_FUNCDECL_SYS (pthread_sigmask, int,
198 (int how,
199 const sigset_t *restrict new_mask,
200 sigset_t *restrict old_mask), );
201 # endif
202 _GL_CXXALIAS_SYS (pthread_sigmask, int,
203 (int how,
204 const sigset_t *restrict new_mask,
205 sigset_t *restrict old_mask));
206 # endif
207 # if __GLIBC__ >= 2
208 _GL_CXXALIASWARN (pthread_sigmask);
209 # endif
210 #elif defined GNULIB_POSIXCHECK
211 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
212 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
213 "use gnulib module pthread_sigmask for portability");
214 # endif
215 #endif
216
217
218 #if @GNULIB_RAISE@
219 # if @REPLACE_RAISE@
220 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
221 # undef raise
222 # define raise rpl_raise
223 # endif
224 _GL_FUNCDECL_RPL (raise, int, (int sig), );
225 _GL_CXXALIAS_RPL (raise, int, (int sig));
226 # else
227 # if !@HAVE_RAISE@
228 _GL_FUNCDECL_SYS (raise, int, (int sig), );
229 # endif
230 _GL_CXXALIAS_SYS (raise, int, (int sig));
231 # endif
232 # if __GLIBC__ >= 2
233 _GL_CXXALIASWARN (raise);
234 # endif
235 #elif defined GNULIB_POSIXCHECK
236 /* Assume raise is always declared. */
237 _GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
238 "use gnulib module raise for portability");
239 #endif
240
241
242 #if @GNULIB_SIGPROCMASK@
243 # if !@HAVE_POSIX_SIGNALBLOCKING@
244
245 # ifndef GNULIB_defined_signal_blocking
246 # define GNULIB_defined_signal_blocking 1
247 # endif
248
249 /* Maximum signal number + 1. */
250 # ifndef NSIG
251 # define NSIG 32
252 # endif
253
254 /* This code supports only 32 signals. */
255 # if !GNULIB_defined_verify_NSIG_constraint
256 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
257 # define GNULIB_defined_verify_NSIG_constraint 1
258 # endif
259
260 # endif
261
262 /* When also using extern inline, suppress the use of static inline in
263 standard headers of problematic Apple configurations, as Libc at
264 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
265 <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
266 Perhaps Apple will fix this some day. */
267 #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
268 && (defined __i386__ || defined __x86_64__))
269 # undef sigaddset
270 # undef sigdelset
271 # undef sigemptyset
272 # undef sigfillset
273 # undef sigismember
274 #endif
275
276 /* Test whether a given signal is contained in a signal set. */
277 # if @HAVE_POSIX_SIGNALBLOCKING@
278 /* This function is defined as a macro on Mac OS X. */
279 # if defined __cplusplus && defined GNULIB_NAMESPACE
280 # undef sigismember
281 # endif
282 # else
283 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig),
284 _GL_ARG_NONNULL ((1)));
285 # endif
286 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
287 _GL_CXXALIASWARN (sigismember);
288
289 /* Initialize a signal set to the empty set. */
290 # if @HAVE_POSIX_SIGNALBLOCKING@
291 /* This function is defined as a macro on Mac OS X. */
292 # if defined __cplusplus && defined GNULIB_NAMESPACE
293 # undef sigemptyset
294 # endif
295 # else
296 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
297 # endif
298 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
299 _GL_CXXALIASWARN (sigemptyset);
300
301 /* Add a signal to a signal set. */
302 # if @HAVE_POSIX_SIGNALBLOCKING@
303 /* This function is defined as a macro on Mac OS X. */
304 # if defined __cplusplus && defined GNULIB_NAMESPACE
305 # undef sigaddset
306 # endif
307 # else
308 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig),
309 _GL_ARG_NONNULL ((1)));
310 # endif
311 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
312 _GL_CXXALIASWARN (sigaddset);
313
314 /* Remove a signal from a signal set. */
315 # if @HAVE_POSIX_SIGNALBLOCKING@
316 /* This function is defined as a macro on Mac OS X. */
317 # if defined __cplusplus && defined GNULIB_NAMESPACE
318 # undef sigdelset
319 # endif
320 # else
321 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig),
322 _GL_ARG_NONNULL ((1)));
323 # endif
324 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
325 _GL_CXXALIASWARN (sigdelset);
326
327 /* Fill a signal set with all possible signals. */
328 # if @HAVE_POSIX_SIGNALBLOCKING@
329 /* This function is defined as a macro on Mac OS X. */
330 # if defined __cplusplus && defined GNULIB_NAMESPACE
331 # undef sigfillset
332 # endif
333 # else
334 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
335 # endif
336 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
337 _GL_CXXALIASWARN (sigfillset);
338
339 /* Return the set of those blocked signals that are pending. */
340 # if !@HAVE_POSIX_SIGNALBLOCKING@
341 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
342 # endif
343 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
344 _GL_CXXALIASWARN (sigpending);
345
346 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
347 Then, if SET is not NULL, affect the current set of blocked signals by
348 combining it with *SET as indicated in OPERATION.
349 In this implementation, you are not allowed to change a signal handler
350 while the signal is blocked. */
351 # if !@HAVE_POSIX_SIGNALBLOCKING@
352 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
353 # define SIG_SETMASK 1 /* blocked_set = *set; */
354 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
355 _GL_FUNCDECL_SYS (sigprocmask, int,
356 (int operation,
357 const sigset_t *restrict set,
358 sigset_t *restrict old_set), );
359 # endif
360 _GL_CXXALIAS_SYS (sigprocmask, int,
361 (int operation,
362 const sigset_t *restrict set,
363 sigset_t *restrict old_set));
364 _GL_CXXALIASWARN (sigprocmask);
365
366 /* Install the handler FUNC for signal SIG, and return the previous
367 handler. */
368 # ifdef __cplusplus
369 extern "C" {
370 # endif
371 # if !GNULIB_defined_function_taking_int_returning_void_t
372 typedef void (*_gl_function_taking_int_returning_void_t) (int);
373 # define GNULIB_defined_function_taking_int_returning_void_t 1
374 # endif
375 # ifdef __cplusplus
376 }
377 # endif
378 # if !@HAVE_POSIX_SIGNALBLOCKING@
379 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
380 # define signal rpl_signal
381 # endif
382 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
383 (int sig, _gl_function_taking_int_returning_void_t func), );
384 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
385 (int sig, _gl_function_taking_int_returning_void_t func));
386 # else
387 /* On OpenBSD, the declaration of 'signal' may not be present at this point,
388 because it occurs in <sys/signal.h>, not <signal.h> directly. */
389 # if defined __OpenBSD__
390 _GL_FUNCDECL_SYS (signal, _gl_function_taking_int_returning_void_t,
391 (int sig, _gl_function_taking_int_returning_void_t func), );
392 # endif
393 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
394 (int sig, _gl_function_taking_int_returning_void_t func));
395 # endif
396 # if __GLIBC__ >= 2
397 _GL_CXXALIASWARN (signal);
398 # endif
399
400 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
401 /* Raise signal SIGPIPE. */
402 _GL_EXTERN_C int _gl_raise_SIGPIPE (void);
403 # endif
404
405 #elif defined GNULIB_POSIXCHECK
406 # if HAVE_RAW_DECL_SIGADDSET
407 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
408 "use the gnulib module sigprocmask for portability");
409 # endif
410 # if HAVE_RAW_DECL_SIGDELSET
411 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
412 "use the gnulib module sigprocmask for portability");
413 # endif
414 # if HAVE_RAW_DECL_SIGEMPTYSET
415 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
416 "use the gnulib module sigprocmask for portability");
417 # endif
418 # if HAVE_RAW_DECL_SIGFILLSET
419 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
420 "use the gnulib module sigprocmask for portability");
421 # endif
422 # if HAVE_RAW_DECL_SIGISMEMBER
423 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
424 "use the gnulib module sigprocmask for portability");
425 # endif
426 # if HAVE_RAW_DECL_SIGPENDING
427 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
428 "use the gnulib module sigprocmask for portability");
429 # endif
430 # if HAVE_RAW_DECL_SIGPROCMASK
431 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
432 "use the gnulib module sigprocmask for portability");
433 # endif
434 #endif /* @GNULIB_SIGPROCMASK@ */
435
436
437 #if @GNULIB_SIGACTION@
438 # if !@HAVE_SIGACTION@
439
440 # if !@HAVE_SIGINFO_T@
441
442 # if !GNULIB_defined_siginfo_types
443
444 /* Present to allow compilation, but unsupported by gnulib. */
445 union sigval
446 {
447 int sival_int;
448 void *sival_ptr;
449 };
450
451 /* Present to allow compilation, but unsupported by gnulib. */
452 struct siginfo_t
453 {
454 int si_signo;
455 int si_code;
456 int si_errno;
457 pid_t si_pid;
458 uid_t si_uid;
459 void *si_addr;
460 int si_status;
461 long si_band;
462 union sigval si_value;
463 };
464 typedef struct siginfo_t siginfo_t;
465
466 # define GNULIB_defined_siginfo_types 1
467 # endif
468
469 # endif /* !@HAVE_SIGINFO_T@ */
470
471 /* We assume that platforms which lack the sigaction() function also lack
472 the 'struct sigaction' type, and vice versa. */
473
474 # if !GNULIB_defined_struct_sigaction
475
476 struct sigaction
477 {
478 union
479 {
480 void (*_sa_handler) (int);
481 /* Present to allow compilation, but unsupported by gnulib. POSIX
482 says that implementations may, but not must, make sa_sigaction
483 overlap with sa_handler, but we know of no implementation where
484 they do not overlap. */
485 void (*_sa_sigaction) (int, siginfo_t *, void *);
486 } _sa_func;
487 sigset_t sa_mask;
488 /* Not all POSIX flags are supported. */
489 int sa_flags;
490 };
491 # define sa_handler _sa_func._sa_handler
492 # define sa_sigaction _sa_func._sa_sigaction
493 /* Unsupported flags are not present. */
494 # define SA_RESETHAND 1
495 # define SA_NODEFER 2
496 # define SA_RESTART 4
497
498 # define GNULIB_defined_struct_sigaction 1
499 # endif
500
501 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
502 struct sigaction *restrict), );
503
504 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
505
506 # define sa_sigaction sa_handler
507
508 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
509
510 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
511 struct sigaction *restrict));
512 _GL_CXXALIASWARN (sigaction);
513
514 #elif defined GNULIB_POSIXCHECK
515 # if HAVE_RAW_DECL_SIGACTION
516 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
517 "use the gnulib module sigaction for portability");
518 # endif
519 #endif
520
521 /* Some systems don't have SA_NODEFER. */
522 #ifndef SA_NODEFER
523 # define SA_NODEFER 0
524 #endif
525
526
527 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
528 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
529 #endif