diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-19 19:22:54 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-19 19:22:54 +0200 |
commit | e854bea3b6837b22e9b6a69acbb28b4c8b470c81 (patch) | |
tree | 008bfee0aba8b1a4762651c604774e17d6d430c9 /sig.c | |
parent | Split into multiple C files (diff) | |
download | deadshred-e854bea3b6837b22e9b6a69acbb28b4c8b470c81.tar.gz deadshred-e854bea3b6837b22e9b6a69acbb28b4c8b470c81.tar.bz2 deadshred-e854bea3b6837b22e9b6a69acbb28b4c8b470c81.tar.xz |
misc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | sig.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -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=<function>, .sa_mask={}, .sa_flags=0} NULL:"); + if (sigaction(SIGINT, &sa, NULL)) + eprintf("sigaction SIGINT {.sa_handler=<function>, .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:"); +} |