Commit | Line | Data |
---|---|---|
95983a02 JG |
1 | /* |
2 | * Copyright (C) - 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU Lesser General Public License as published by the | |
6 | * Free Software Foundation; version 2.1 of the License. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
11 | * for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public License | |
14 | * along with this library; if not, write to the Free Software Foundation, | |
15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
18 | #ifndef LTTNG_TESTAPP_SIGNAL_HELPER_H | |
19 | #define LTTNG_TESTAPP_SIGNAL_HELPER_H | |
20 | ||
21 | #include <signal.h> | |
22 | ||
23 | static volatile int should_quit; | |
24 | ||
25 | static | |
26 | void sighandler(int sig) | |
27 | { | |
28 | if (sig == SIGTERM) { | |
29 | should_quit = 1; | |
30 | } | |
31 | } | |
32 | ||
33 | static | |
34 | int set_signal_handler(void) | |
35 | { | |
36 | int ret; | |
37 | struct sigaction sa = { | |
38 | .sa_flags = 0, | |
39 | .sa_handler = sighandler, | |
40 | }; | |
41 | ||
42 | ret = sigemptyset(&sa.sa_mask); | |
43 | if (ret) { | |
44 | perror("sigemptyset"); | |
45 | goto end; | |
46 | } | |
47 | ||
48 | ret = sigaction(SIGTERM, &sa, NULL); | |
49 | if (ret) { | |
50 | perror("sigaction"); | |
51 | goto end; | |
52 | } | |
53 | end: | |
54 | return ret; | |
55 | } | |
56 | ||
57 | #endif /* LTTNG_TESTAPP_SIGNAL_HELPER_H */ |