chiark / gitweb /
tree-wide: drop license boilerplate
[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 int signal_from_string_try_harder(const char *s);
30 #if 0 /// UNNEEDED by elogind
31
32 void nop_signal_handler(int sig);
33 #endif // 0
34
35 static inline void block_signals_reset(sigset_t *ss) {
36         assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0);
37 }
38
39 #define BLOCK_SIGNALS(...)                                                         \
40         _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({        \
41                 sigset_t _t;                                                       \
42                 assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__, -1) >= 0); \
43                 _t;                                                                \
44         })
45
46 static inline bool SIGNAL_VALID(int signo) {
47         return signo > 0 && signo < _NSIG;
48 }
49
50 static inline const char* signal_to_string_with_check(int n) {
51         if (!SIGNAL_VALID(n))
52                 return NULL;
53
54         return signal_to_string(n);
55 }