diff options
author | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
commit | 420d2ef464d4a741028e132e662d5626806a41f5 (patch) | |
tree | 1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/signal_handler.hpp |
Diffstat (limited to 'core/signal_handler.hpp')
-rw-r--r-- | core/signal_handler.hpp | 34 |
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= |