tests: compile some tools/tests as C++
[lttng-tools.git] / tests / utils / testapp / signal-helper.h
1 /*
2 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TESTAPP_SIGNAL_HELPER_H
9 #define LTTNG_TESTAPP_SIGNAL_HELPER_H
10
11 #include <signal.h>
12
13 static volatile int should_quit;
14
15 static
16 void sighandler(int sig)
17 {
18 if (sig == SIGTERM) {
19 should_quit = 1;
20 }
21 }
22
23 static
24 int set_signal_handler(void)
25 {
26 int ret;
27 struct sigaction sa {};
28 sa.sa_flags = 0;
29 sa.sa_handler = sighandler;
30
31 ret = sigemptyset(&sa.sa_mask);
32 if (ret) {
33 perror("sigemptyset");
34 goto end;
35 }
36
37 ret = sigaction(SIGTERM, &sa, NULL);
38 if (ret) {
39 perror("sigaction");
40 goto end;
41 }
42 end:
43 return ret;
44 }
45
46 #endif /* LTTNG_TESTAPP_SIGNAL_HELPER_H */
This page took 0.032798 seconds and 5 git commands to generate.