]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
24882e06 LP |
2 | #pragma once |
3 | ||
24882e06 LP |
4 | #include <signal.h> |
5 | ||
6 | #include "macro.h" | |
7 | ||
8 | int reset_all_signal_handlers(void); | |
9 | int reset_signal_mask(void); | |
10 | ||
11 | int ignore_signals(int sig, ...); | |
12 | int default_signals(int sig, ...); | |
13 | int sigaction_many(const struct sigaction *sa, ...); | |
14 | ||
0c2c2a3a | 15 | int sigset_add_many(sigset_t *ss, ...); |
72c0a2c2 | 16 | int sigprocmask_many(int how, sigset_t *old, ...); |
24882e06 LP |
17 | |
18 | const char *signal_to_string(int i) _const_; | |
19 | int signal_from_string(const char *s) _pure_; | |
20 | ||
6bedfcbb | 21 | void nop_signal_handler(int sig); |
0c5eb056 LP |
22 | |
23 | static inline void block_signals_reset(sigset_t *ss) { | |
24 | assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0); | |
25 | } | |
26 | ||
7c78959f LP |
27 | #define BLOCK_SIGNALS(...) \ |
28 | _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({ \ | |
29 | sigset_t _t; \ | |
30 | assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__, -1) >= 0); \ | |
31 | _t; \ | |
0c5eb056 | 32 | }) |
6eb7c172 LP |
33 | |
34 | static inline bool SIGNAL_VALID(int signo) { | |
35 | return signo > 0 && signo < _NSIG; | |
36 | } | |
33d12153 YW |
37 | |
38 | static inline const char* signal_to_string_with_check(int n) { | |
39 | if (!SIGNAL_VALID(n)) | |
40 | return NULL; | |
41 | ||
42 | return signal_to_string(n); | |
43 | } |