diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-25 12:11:59 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-07-08 10:33:38 +0200 |
commit | 0178ff292b1befb5149c16e62e7ab12b0ef83954 (patch) | |
tree | ab9f1f278bc131d348583deced161f95e09f3c26 /src/basic/signal-util.c | |
parent | hostnamed: correct variable with errno in fallback_chassis (diff) | |
download | systemd-0178ff292b1befb5149c16e62e7ab12b0ef83954.tar.xz systemd-0178ff292b1befb5149c16e62e7ab12b0ef83954.zip |
signal-util: add helper pop_pending_signal()
Diffstat (limited to 'src/basic/signal-util.c')
-rw-r--r-- | src/basic/signal-util.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 131fd3ba00..b06b5ce774 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -253,3 +253,38 @@ int signal_is_blocked(int sig) { return r; } + +int pop_pending_signal_internal(int sig, ...) { + sigset_t ss; + va_list ap; + int r; + + if (sig < 0) /* Empty list? */ + return -EINVAL; + + if (sigemptyset(&ss) < 0) + return -errno; + + /* Add first signal (if the signal is zero, we'll silently skip it, to make it easiert to build + * parameter lists where some element are sometimes off, similar to how sigset_add_many_ap() handles + * this.) */ + if (sig > 0 && sigaddset(&ss, sig) < 0) + return -errno; + + /* Add all other signals */ + va_start(ap, sig); + r = sigset_add_many_ap(&ss, ap); + va_end(ap); + if (r < 0) + return r; + + r = sigtimedwait(&ss, NULL, &(struct timespec) { 0, 0 }); + if (r < 0) { + if (errno == EAGAIN) + return 0; + + return -errno; + } + + return r; /* Returns the signal popped */ +} |