summaryrefslogtreecommitdiff
path: root/core/signal_handler.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/signal_handler.hpp')
-rw-r--r--core/signal_handler.hpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/signal_handler.hpp b/core/signal_handler.hpp
new file mode 100644
index 0000000..87a1353
--- /dev/null
+++ b/core/signal_handler.hpp
@@ -0,0 +1,34 @@
+#ifndef WvCIARcg6KvWbOCcoxmM1lc74OI
+#define WvCIARcg6KvWbOCcoxmM1lc74OI
+
+#include <assert.h>
+#include <signal.h>
+
+volatile bool terminationRequested = false;
+
+void sigIntHandler(int sig) {
+ terminationRequested = true;
+}
+
+void installSigIntHandler() {
+ struct sigaction action;
+ action.sa_handler = sigIntHandler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ assert(sigaction(SIGINT, &action, NULL) == 0);
+
+}
+
+void sigIntExit() {
+ // restore old SIG INT handler ...
+ struct sigaction action;
+ action.sa_handler = SIG_DFL;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ assert(sigaction(SIGINT, &action, NULL) == 0);
+
+ // ... and use it for suicide
+ kill(getpid(), SIGINT);
+}
+
+#endif // WvCIARcg6KvWbOCcoxmM1lc74OI=
contact: Jan Huwald // Impressum