Commit | Line | Data |
---|---|---|
95983a02 | 1 | /* |
9d16b343 | 2 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
95983a02 | 3 | * |
9d16b343 | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
95983a02 | 5 | * |
95983a02 JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_TESTAPP_SIGNAL_HELPER_H | |
9 | #define LTTNG_TESTAPP_SIGNAL_HELPER_H | |
10 | ||
11 | #include <signal.h> | |
52e345b9 | 12 | #include <stdio.h> |
95983a02 JG |
13 | |
14 | static volatile int should_quit; | |
15 | ||
16 | static | |
17 | void sighandler(int sig) | |
18 | { | |
19 | if (sig == SIGTERM) { | |
20 | should_quit = 1; | |
21 | } | |
22 | } | |
23 | ||
24 | static | |
cd9adb8b | 25 | int set_signal_handler() |
95983a02 JG |
26 | { |
27 | int ret; | |
729c1fec SM |
28 | struct sigaction sa {}; |
29 | sa.sa_flags = 0; | |
30 | sa.sa_handler = sighandler; | |
95983a02 JG |
31 | |
32 | ret = sigemptyset(&sa.sa_mask); | |
33 | if (ret) { | |
34 | perror("sigemptyset"); | |
35 | goto end; | |
36 | } | |
37 | ||
cd9adb8b | 38 | ret = sigaction(SIGTERM, &sa, nullptr); |
95983a02 JG |
39 | if (ret) { |
40 | perror("sigaction"); | |
41 | goto end; | |
42 | } | |
43 | end: | |
44 | return ret; | |
45 | } | |
46 | ||
47 | #endif /* LTTNG_TESTAPP_SIGNAL_HELPER_H */ |