Debian Codegraph @

lib/signal.in.h

raw
1 /* A GNU-like <signal.h>.
2
3 Copyright (C) 2006-2024 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 _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. */
34
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
36
37 #else
38 /* Normal invocation convention. */
39
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
41
42 #define _GL_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 _GL_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, OSF/1 4.0, 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 __osf__ || 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 # undef sig2str
160 # if HAVE_RAW_DECL_SIG2STR
161 _GL_WARN_ON_USE (sig2str, "sig2str is not portable - "
162 "use gnulib module sig2str for portability");
163 # endif
164 #endif
165
166 #if @GNULIB_SIG2STR@
167 # if !@HAVE_STR2SIG@
168 _GL_FUNCDECL_SYS (str2sig, int, (char const *str, int *signo_p), );
169 # endif
170 _GL_CXXALIAS_SYS (str2sig, int, (char const *str, int *signo_p));
171 # if __GLIBC__ >= 2
172 _GL_CXXALIASWARN (str2sig);
173 # endif
174 #elif defined GNULIB_POSIXCHECK
175 # undef str2sig
176 # if HAVE_RAW_DECL_STR2SIG
177 _GL_WARN_ON_USE (str2sig, "str2sig is not portable - "
178 "use gnulib module sig2str for portability");
179 # endif
180 #endif
181
182
183 #if @GNULIB_PTHREAD_SIGMASK@
184 # if @REPLACE_PTHREAD_SIGMASK@
185 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186 # undef pthread_sigmask
187 # define pthread_sigmask rpl_pthread_sigmask
188 # endif
189 _GL_FUNCDECL_RPL (pthread_sigmask, int,
190 (int how,
191 const sigset_t *restrict new_mask,
192 sigset_t *restrict old_mask), );
193 _GL_CXXALIAS_RPL (pthread_sigmask, int,
194 (int how,
195 const sigset_t *restrict new_mask,
196 sigset_t *restrict old_mask));
197 # else
198 # if !(@HAVE_PTHREAD_SIGMASK@ || defined pthread_sigmask)
199 _GL_FUNCDECL_SYS (pthread_sigmask, int,
200 (int how,
201 const sigset_t *restrict new_mask,
202 sigset_t *restrict old_mask), );
203 # endif
204 _GL_CXXALIAS_SYS (pthread_sigmask, int,
205 (int how,
206 const sigset_t *restrict new_mask,
207 sigset_t *restrict old_mask));
208 # endif
209 # if __GLIBC__ >= 2
210 _GL_CXXALIASWARN (pthread_sigmask);
211 # endif
212 #elif defined GNULIB_POSIXCHECK
213 # undef pthread_sigmask
214 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
215 _GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
216 "use gnulib module pthread_sigmask for portability");
217 # endif
218 #endif
219
220
221 #if @GNULIB_RAISE@
222 # if @REPLACE_RAISE@
223 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # undef raise
225 # define raise rpl_raise
226 # endif
227 _GL_FUNCDECL_RPL (raise, int, (int sig), );
228 _GL_CXXALIAS_RPL (raise, int, (int sig));
229 # else
230 # if !@HAVE_RAISE@
231 _GL_FUNCDECL_SYS (raise, int, (int sig), );
232 # endif
233 _GL_CXXALIAS_SYS (raise, int, (int sig));
234 # endif
235 # if __GLIBC__ >= 2
236 _GL_CXXALIASWARN (raise);
237 # endif
238 #elif defined GNULIB_POSIXCHECK
239 # undef raise
240 /* Assume raise is always declared. */
241 _GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
242 "use gnulib module raise for portability");
243 #endif
244
245
246 #if @GNULIB_SIGPROCMASK@
247 # if !@HAVE_POSIX_SIGNALBLOCKING@
248
249 # ifndef GNULIB_defined_signal_blocking
250 # define GNULIB_defined_signal_blocking 1
251 # endif
252
253 /* Maximum signal number + 1. */
254 # ifndef NSIG
255 # define NSIG 32
256 # endif
257
258 /* This code supports only 32 signals. */
259 # if !GNULIB_defined_verify_NSIG_constraint
260 typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
261 # define GNULIB_defined_verify_NSIG_constraint 1
262 # endif
263
264 # endif
265
266 /* When also using extern inline, suppress the use of static inline in
267 standard headers of problematic Apple configurations, as Libc at
268 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
269 <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
270 Perhaps Apple will fix this some day. */
271 #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
272 && (defined __i386__ || defined __x86_64__))
273 # undef sigaddset
274 # undef sigdelset
275 # undef sigemptyset
276 # undef sigfillset
277 # undef sigismember
278 #endif
279
280 /* Test whether a given signal is contained in a signal set. */
281 # if @HAVE_POSIX_SIGNALBLOCKING@
282 /* This function is defined as a macro on Mac OS X. */
283 # if defined __cplusplus && defined GNULIB_NAMESPACE
284 # undef sigismember
285 # endif
286 # else
287 _GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig),
288 _GL_ARG_NONNULL ((1)));
289 # endif
290 _GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
291 _GL_CXXALIASWARN (sigismember);
292
293 /* Initialize a signal set to the empty set. */
294 # if @HAVE_POSIX_SIGNALBLOCKING@
295 /* This function is defined as a macro on Mac OS X. */
296 # if defined __cplusplus && defined GNULIB_NAMESPACE
297 # undef sigemptyset
298 # endif
299 # else
300 _GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
301 # endif
302 _GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
303 _GL_CXXALIASWARN (sigemptyset);
304
305 /* Add a signal to a signal set. */
306 # if @HAVE_POSIX_SIGNALBLOCKING@
307 /* This function is defined as a macro on Mac OS X. */
308 # if defined __cplusplus && defined GNULIB_NAMESPACE
309 # undef sigaddset
310 # endif
311 # else
312 _GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig),
313 _GL_ARG_NONNULL ((1)));
314 # endif
315 _GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
316 _GL_CXXALIASWARN (sigaddset);
317
318 /* Remove a signal from a signal set. */
319 # if @HAVE_POSIX_SIGNALBLOCKING@
320 /* This function is defined as a macro on Mac OS X. */
321 # if defined __cplusplus && defined GNULIB_NAMESPACE
322 # undef sigdelset
323 # endif
324 # else
325 _GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig),
326 _GL_ARG_NONNULL ((1)));
327 # endif
328 _GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
329 _GL_CXXALIASWARN (sigdelset);
330
331 /* Fill a signal set with all possible signals. */
332 # if @HAVE_POSIX_SIGNALBLOCKING@
333 /* This function is defined as a macro on Mac OS X. */
334 # if defined __cplusplus && defined GNULIB_NAMESPACE
335 # undef sigfillset
336 # endif
337 # else
338 _GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
339 # endif
340 _GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
341 _GL_CXXALIASWARN (sigfillset);
342
343 /* Return the set of those blocked signals that are pending. */
344 # if !@HAVE_POSIX_SIGNALBLOCKING@
345 _GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set), _GL_ARG_NONNULL ((1)));
346 # endif
347 _GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
348 _GL_CXXALIASWARN (sigpending);
349
350 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
351 Then, if SET is not NULL, affect the current set of blocked signals by
352 combining it with *SET as indicated in OPERATION.
353 In this implementation, you are not allowed to change a signal handler
354 while the signal is blocked. */
355 # if !@HAVE_POSIX_SIGNALBLOCKING@
356 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
357 # define SIG_SETMASK 1 /* blocked_set = *set; */
358 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
359 _GL_FUNCDECL_SYS (sigprocmask, int,
360 (int operation,
361 const sigset_t *restrict set,
362 sigset_t *restrict old_set), );
363 # endif
364 _GL_CXXALIAS_SYS (sigprocmask, int,
365 (int operation,
366 const sigset_t *restrict set,
367 sigset_t *restrict old_set));
368 _GL_CXXALIASWARN (sigprocmask);
369
370 /* Install the handler FUNC for signal SIG, and return the previous
371 handler. */
372 # ifdef __cplusplus
373 extern "C" {
374 # endif
375 # if !GNULIB_defined_function_taking_int_returning_void_t
376 typedef void (*_gl_function_taking_int_returning_void_t) (int);
377 # define GNULIB_defined_function_taking_int_returning_void_t 1
378 # endif
379 # ifdef __cplusplus
380 }
381 # endif
382 # if !@HAVE_POSIX_SIGNALBLOCKING@
383 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
384 # define signal rpl_signal
385 # endif
386 _GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
387 (int sig, _gl_function_taking_int_returning_void_t func), );
388 _GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
389 (int sig, _gl_function_taking_int_returning_void_t func));
390 # else
391 /* On OpenBSD, the declaration of 'signal' may not be present at this point,
392 because it occurs in <sys/signal.h>, not <signal.h> directly. */
393 # if defined __OpenBSD__
394 _GL_FUNCDECL_SYS (signal, _gl_function_taking_int_returning_void_t,
395 (int sig, _gl_function_taking_int_returning_void_t func), );
396 # endif
397 _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
398 (int sig, _gl_function_taking_int_returning_void_t func));
399 # endif
400 # if __GLIBC__ >= 2
401 _GL_CXXALIASWARN (signal);
402 # endif
403
404 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
405 /* Raise signal SIGPIPE. */
406 _GL_EXTERN_C int _gl_raise_SIGPIPE (void);
407 # endif
408
409 #elif defined GNULIB_POSIXCHECK
410 # undef sigaddset
411 # if HAVE_RAW_DECL_SIGADDSET
412 _GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
413 "use the gnulib module sigprocmask for portability");
414 # endif
415 # undef sigdelset
416 # if HAVE_RAW_DECL_SIGDELSET
417 _GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
418 "use the gnulib module sigprocmask for portability");
419 # endif
420 # undef sigemptyset
421 # if HAVE_RAW_DECL_SIGEMPTYSET
422 _GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
423 "use the gnulib module sigprocmask for portability");
424 # endif
425 # undef sigfillset
426 # if HAVE_RAW_DECL_SIGFILLSET
427 _GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
428 "use the gnulib module sigprocmask for portability");
429 # endif
430 # undef sigismember
431 # if HAVE_RAW_DECL_SIGISMEMBER
432 _GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
433 "use the gnulib module sigprocmask for portability");
434 # endif
435 # undef sigpending
436 # if HAVE_RAW_DECL_SIGPENDING
437 _GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
438 "use the gnulib module sigprocmask for portability");
439 # endif
440 # undef sigprocmask
441 # if HAVE_RAW_DECL_SIGPROCMASK
442 _GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
443 "use the gnulib module sigprocmask for portability");
444 # endif
445 #endif /* @GNULIB_SIGPROCMASK@ */
446
447
448 #if @GNULIB_SIGACTION@
449 # if !@HAVE_SIGACTION@
450
451 # if !@HAVE_SIGINFO_T@
452
453 # if !GNULIB_defined_siginfo_types
454
455 /* Present to allow compilation, but unsupported by gnulib. */
456 union sigval
457 {
458 int sival_int;
459 void *sival_ptr;
460 };
461
462 /* Present to allow compilation, but unsupported by gnulib. */
463 struct siginfo_t
464 {
465 int si_signo;
466 int si_code;
467 int si_errno;
468 pid_t si_pid;
469 uid_t si_uid;
470 void *si_addr;
471 int si_status;
472 long si_band;
473 union sigval si_value;
474 };
475 typedef struct siginfo_t siginfo_t;
476
477 # define GNULIB_defined_siginfo_types 1
478 # endif
479
480 # endif /* !@HAVE_SIGINFO_T@ */
481
482 /* We assume that platforms which lack the sigaction() function also lack
483 the 'struct sigaction' type, and vice versa. */
484
485 # if !GNULIB_defined_struct_sigaction
486
487 struct sigaction
488 {
489 union
490 {
491 void (*_sa_handler) (int);
492 /* Present to allow compilation, but unsupported by gnulib. POSIX
493 says that implementations may, but not must, make sa_sigaction
494 overlap with sa_handler, but we know of no implementation where
495 they do not overlap. */
496 void (*_sa_sigaction) (int, siginfo_t *, void *);
497 } _sa_func;
498 sigset_t sa_mask;
499 /* Not all POSIX flags are supported. */
500 int sa_flags;
501 };
502 # define sa_handler _sa_func._sa_handler
503 # define sa_sigaction _sa_func._sa_sigaction
504 /* Unsupported flags are not present. */
505 # define SA_RESETHAND 1
506 # define SA_NODEFER 2
507 # define SA_RESTART 4
508
509 # define GNULIB_defined_struct_sigaction 1
510 # endif
511
512 _GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
513 struct sigaction *restrict), );
514
515 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
516
517 # define sa_sigaction sa_handler
518
519 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
520
521 _GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
522 struct sigaction *restrict));
523 _GL_CXXALIASWARN (sigaction);
524
525 #elif defined GNULIB_POSIXCHECK
526 # undef sigaction
527 # if HAVE_RAW_DECL_SIGACTION
528 _GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
529 "use the gnulib module sigaction for portability");
530 # endif
531 #endif
532
533 /* Some systems don't have SA_NODEFER. */
534 #ifndef SA_NODEFER
535 # define SA_NODEFER 0
536 #endif
537
538
539 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
540 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
541 #endif