Rename C++ header files to .hpp
[lttng-tools.git] / tests / utils / testapp / signal-helper.hpp
diff --git a/tests/utils/testapp/signal-helper.hpp b/tests/utils/testapp/signal-helper.hpp
new file mode 100644 (file)
index 0000000..ceadcb3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_TESTAPP_SIGNAL_HELPER_H
+#define LTTNG_TESTAPP_SIGNAL_HELPER_H
+
+#include <signal.h>
+
+static volatile int should_quit;
+
+static
+void sighandler(int sig)
+{
+       if (sig == SIGTERM) {
+               should_quit = 1;
+       }
+}
+
+static
+int set_signal_handler(void)
+{
+       int ret;
+       struct sigaction sa {};
+       sa.sa_flags = 0;
+       sa.sa_handler = sighandler;
+
+       ret = sigemptyset(&sa.sa_mask);
+       if (ret) {
+               perror("sigemptyset");
+               goto end;
+       }
+
+       ret = sigaction(SIGTERM, &sa, NULL);
+       if (ret) {
+               perror("sigaction");
+               goto end;
+       }
+end:
+       return ret;
+}
+
+#endif /* LTTNG_TESTAPP_SIGNAL_HELPER_H */
This page took 0.028184 seconds and 4 git commands to generate.