summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-28 16:13:42 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-28 19:13:29 +0200
commitb04cdd61fbeb8502125b416e048f0b6e239369e7 (patch)
treed4e2f3bcdfe5f8bb94643aa9536d85cd01aefc8a
parentdff4f960481fc5916ac1c19ebbd38e8023406309 (diff)
Add backtrace on errors
Change-Id: Id2ce3a62d97fd4148d661b34f7507d7a4bec4fba Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/sig-monitor.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/sig-monitor.c b/src/sig-monitor.c
index aaffaed0..fdaf8c09 100644
--- a/src/sig-monitor.c
+++ b/src/sig-monitor.c
@@ -24,6 +24,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/syscall.h>
+#include <execinfo.h>
#include "sig-monitor.h"
#include "verbose.h"
@@ -38,6 +39,26 @@ static _Thread_local int thread_timer_set;
static _Thread_local timer_t thread_timerid;
/*
+ * Dumps the current stack
+ */
+static void dumpstack(int crop)
+{
+ int idx, count;
+ void *addresses[1000];
+ char **locations;
+
+ count = backtrace(addresses, sizeof addresses / sizeof *addresses);
+ locations = backtrace_symbols(addresses, count);
+ if (locations == NULL)
+ ERROR("can't get the backtrace (returned %d addresses)", count);
+ else {
+ for (idx = crop; idx < count; idx++)
+ ERROR("[BACKTRACE %d/%d] %s", idx - crop + 1, count - crop, locations[idx]);
+ free(locations);
+ }
+}
+
+/*
* Creates a timer for the current thread
*
* Returns 0 in case of success
@@ -118,6 +139,10 @@ static void on_signal_error(int signum)
sigset_t sigset;
ERROR("ALERT! signal %d received: %s", signum, strsignal(signum));
+ if (error_handler == NULL && signum == SIG_FOR_TIMER)
+ return;
+
+ dumpstack(3);
// unlock signal to allow a new signal to come
if (error_handler != NULL) {
@@ -126,8 +151,6 @@ static void on_signal_error(int signum)
sigprocmask(SIG_UNBLOCK, &sigset, 0);
longjmp(*error_handler, signum);
}
- if (signum == SIG_FOR_TIMER)
- return;
ERROR("Unmonitored signal %d received: %s", signum, strsignal(signum));
exit(2);
}