From e854bea3b6837b22e9b6a69acbb28b4c8b470c81 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 19 Sep 2024 19:22:54 +0200 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- sig.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 sig.c (limited to 'sig.c') diff --git a/sig.c b/sig.c new file mode 100644 index 0000000..c7900fd --- /dev/null +++ b/sig.c @@ -0,0 +1,50 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +static void +sighandler(int signo) +{ + (void) signo; + exiting = 1; +} + + +void +setup_sighandler(void) +{ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = &sighandler; + sigemptyset(&sa.sa_mask); + if (sigaction(SIGTERM, &sa, NULL)) + eprintf("sigaction SIGTERM {.sa_handler=, .sa_mask={}, .sa_flags=0} NULL:"); + if (sigaction(SIGINT, &sa, NULL)) + eprintf("sigaction SIGINT {.sa_handler=, .sa_mask={}, .sa_flags=0} NULL:"); +} + + +void +block_sigs(void) +{ + sigset_t sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGTERM); + sigaddset(&sigset, SIGINT); + errno = pthread_sigmask(SIG_BLOCK, &sigset, NULL); + if (errno) + eprintf("pthread_sigmask SIG_BLOCK {SIGTERM, SIGINT} NULL:"); +} + + +void +unblock_sigs(void) +{ + sigset_t sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGTERM); + sigaddset(&sigset, SIGINT); + errno = pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); + if (errno) + eprintf("pthread_sigmask SIG_UNBLOCK {SIGTERM, SIGINT} NULL:"); +} -- cgit v1.2.3-70-g09d2