chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / basic / signal-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5   Copyright 2010-2015 Lennart Poettering
6 ***/
7
8 #include <signal.h>
9
10 #include "macro.h"
11
12 int reset_all_signal_handlers(void);
13 int reset_signal_mask(void);
14
15 int ignore_signals(int sig, ...);
16 int default_signals(int sig, ...);
17 #if 0 /// UNNEEDED by elogind
18 int sigaction_many(const struct sigaction *sa, ...);
19 #endif // 0
20
21 int sigset_add_many(sigset_t *ss, ...);
22 int sigprocmask_many(int how, sigset_t *old, ...);
23
24 const char *signal_to_string(int i) _const_;
25 int signal_from_string(const char *s) _pure_;
26
27 #if 0 /// UNNEEDED by elogind
28 void nop_signal_handler(int sig);
29 #endif // 0
30
31 static inline void block_signals_reset(sigset_t *ss) {
32         assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0);
33 }
34
35 #define BLOCK_SIGNALS(...)                                                         \
36         _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({        \
37                 sigset_t _t;                                                       \
38                 assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__, -1) >= 0); \
39                 _t;                                                                \
40         })
41
42 static inline bool SIGNAL_VALID(int signo) {
43         return signo > 0 && signo < _NSIG;
44 }
45
46 static inline const char* signal_to_string_with_check(int n) {
47         if (!SIGNAL_VALID(n))
48                 return NULL;
49
50         return signal_to_string(n);
51 }