aboutsummaryrefslogtreecommitdiff
path: root/src/util/timeout.c
diff options
context:
space:
mode:
authorJ08nY2017-10-04 18:41:47 +0200
committerJ08nY2017-10-04 18:41:47 +0200
commitcaa000e3625241b930fdcda1594bbaf9c9acf642 (patch)
tree2eb6ce02a3a172bd2cf4463d45bcbd7954589e31 /src/util/timeout.c
parent45c08cad912299a8d2043e432bb38e003151526b (diff)
downloadecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.tar.gz
ecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.tar.zst
ecgen-caa000e3625241b930fdcda1594bbaf9c9acf642.zip
Diffstat (limited to 'src/util/timeout.c')
-rw-r--r--src/util/timeout.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/util/timeout.c b/src/util/timeout.c
index 51138fd..c9e20e0 100644
--- a/src/util/timeout.c
+++ b/src/util/timeout.c
@@ -3,18 +3,26 @@
* Copyright (C) 2017 J08nY
*/
#include "timeout.h"
-#include <signal.h>
-__thread jmp_buf exception;
+__thread jmp_buf timeout_ptr;
+__thread bool timeout_in;
+__thread timer_t timeout_timer;
-void timeout_handle(int signum) { longjmp(exception, 1); }
+void timeout_handle(int signum, siginfo_t *siginfo, void *other) {
+ sigset_t mask;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGALRM);
+ sigprocmask(SIG_UNBLOCK, &mask, NULL);
+
+ if (timeout_in) siglongjmp(timeout_ptr, 1);
+}
bool timeout_init(const config_t *cfg) {
struct sigaction new_action;
- new_action.sa_handler = timeout_handle;
+ new_action.sa_sigaction = timeout_handle;
sigemptyset(&new_action.sa_mask);
- new_action.sa_flags = 0;
+ new_action.sa_flags = SA_SIGINFO;
sigaction(SIGALRM, &new_action, NULL);
return true;