chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / basic / signal-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
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 #if 0 /// UNNEEDED by elogind
14 int sigaction_many(const struct sigaction *sa, ...);
15 #endif // 0
16
17 int sigset_add_many(sigset_t *ss, ...);
18 int sigprocmask_many(int how, sigset_t *old, ...);
19
20 const char *signal_to_string(int i) _const_;
21 int signal_from_string(const char *s) _pure_;
22
23 #if 0 /// UNNEEDED by elogind
24 void nop_signal_handler(int sig);
25 #endif // 0
26
27 static inline void block_signals_reset(sigset_t *ss) {
28         assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0);
29 }
30
31 #define BLOCK_SIGNALS(...)                                                         \
32         _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({        \
33                 sigset_t _t;                                                       \
34                 assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__, -1) >= 0); \
35                 _t;                                                                \
36         })
37
38 static inline bool SIGNAL_VALID(int signo) {
39         return signo > 0 && signo < _NSIG;
40 }
41
42 static inline const char* signal_to_string_with_check(int n) {
43         if (!SIGNAL_VALID(n))
44                 return NULL;
45
46         return signal_to_string(n);
47 }