-
Notifications
You must be signed in to change notification settings - Fork 6
/
walkthroughd.c
45 lines (36 loc) · 1.14 KB
/
walkthroughd.c
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
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
/* Let's define assert_se() as guaranteed side effect version of assert(): even if NDEBUG is set the commands specified
* are executed. */
#ifdef NDEBUG
#define assert_se(x) (void) (x)
#else
#define assert_se(x) assert(x)
#endif
int main(int argc, char *argv[]) {
sigset_t ss;
int sig;
fprintf(stderr, "Initializing.\n");
assert_se(sigemptyset(&ss) >= 0);
assert_se(sigaddset(&ss, SIGTERM) >= 0);
assert_se(sigaddset(&ss, SIGINT) >= 0);
assert_se(sigprocmask(SIG_BLOCK, &ss, NULL) >= 0);
if (sigwait(&ss, &sig) < 0) {
fprintf(stderr, "Failed to sigwait(): %m\n");
goto fail;
}
if (sig == SIGTERM)
fprintf(stderr, "Got SIGTERM.\n");
else {
assert(sig == SIGINT);
fprintf(stderr, "Got SIGINT.\n");
}
fprintf(stderr, "Exiting cleanly.\n");
return EXIT_SUCCESS;
fail:
fprintf(stderr, "Exiting with failure.\n");
return EXIT_FAILURE;
}