]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/signal-util.h
f6c3396ebe6d64157ab19353a07f048a9334f593
[thirdparty/systemd.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 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <signal.h>
24
25 #include "macro.h"
26
27 int reset_all_signal_handlers(void);
28 int reset_signal_mask(void);
29
30 int ignore_signals(int sig, ...);
31 int default_signals(int sig, ...);
32 int sigaction_many(const struct sigaction *sa, ...);
33
34 int sigset_add_many(sigset_t *ss, ...);
35 int sigprocmask_many(int how, sigset_t *old, ...);
36
37 const char *signal_to_string(int i) _const_;
38 int signal_from_string(const char *s) _pure_;
39
40 int signal_from_string_try_harder(const char *s);
41
42 void nop_signal_handler(int sig);
43
44 static inline void block_signals_reset(sigset_t *ss) {
45 assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0);
46 }
47
48 #define BLOCK_SIGNALS(...) \
49 _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({ \
50 sigset_t _t; \
51 assert_se(sigprocmask_many(SIG_BLOCK, &_t, __VA_ARGS__, -1) >= 0); \
52 _t; \
53 })
54
55 static inline bool SIGNAL_VALID(int signo) {
56 return signo > 0 && signo < _NSIG;
57 }
58
59 static inline const char* signal_to_string_with_check(int n) {
60 if (!SIGNAL_VALID(n))
61 return NULL;
62
63 return signal_to_string(n);
64 }