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