X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fsignal-util.h;h=ee37e2726e14e686cad101ea0b0946f6eb9567e1;hb=26f0d9bd01bb3047c31e8e9586f47440cbce50bd;hp=1cdd984a7f4c7fc62cbffab4938c910fed3587e2;hpb=da2587d5154e11d4e643e326793f3ce2cc48dee6;p=elogind.git diff --git a/src/basic/signal-util.h b/src/basic/signal-util.h index 1cdd984a7..ee37e2726 100644 --- a/src/basic/signal-util.h +++ b/src/basic/signal-util.h @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - #pragma once /*** @@ -42,5 +40,21 @@ int signal_from_string(const char *s) _pure_; int signal_from_string_try_harder(const char *s); #if 0 /// UNNEEDED by elogind + void nop_signal_handler(int sig); #endif // 0 + +static inline void block_signals_reset(sigset_t *ss) { + assert_se(sigprocmask(SIG_SETMASK, ss, NULL) >= 0); +} + +#define BLOCK_SIGNALS(...) \ + _cleanup_(block_signals_reset) _unused_ sigset_t _saved_sigset = ({ \ + sigset_t t; \ + assert_se(sigprocmask_many(SIG_BLOCK, &t, __VA_ARGS__, -1) >= 0); \ + t; \ + }) + +static inline bool SIGNAL_VALID(int signo) { + return signo > 0 && signo < _NSIG; +}