aboutsummaryrefslogtreecommitdiffstats
path: root/sig.c
blob: c7900fd62528f6fac13e5ea13e3aefee95f33523 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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:");
}