X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsig-monitor.c;h=bd1311a9620c75edb521adc258068562c7a29e01;hb=bdff72f45e1d02f596595f6229d5bccf7c0827c2;hp=1e5193517093d927209365464a7fd329cb1be9e6;hpb=e285cfb2219eb5a1034208efaf6d1a2d875c721f;p=src%2Fapp-framework-binder.git diff --git a/src/sig-monitor.c b/src/sig-monitor.c index 1e519351..bd1311a9 100644 --- a/src/sig-monitor.c +++ b/src/sig-monitor.c @@ -24,11 +24,12 @@ #include #include #include +#include #include "sig-monitor.h" #include "verbose.h" -#define SIG_FOR_TIMER (SIGVTALRM+2) +#define SIG_FOR_TIMER SIGVTALRM /* local handler */ static _Thread_local sigjmp_buf *error_handler; @@ -37,6 +38,26 @@ static _Thread_local sigjmp_buf *error_handler; 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 * @@ -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); } @@ -148,8 +171,8 @@ static int install(void (*handler)(int), int *signals) int sig_monitor_init() { - static int sigerr[] = { SIG_FOR_TIMER, SIGSEGV, SIGFPE, 0 }; - static int sigterm[] = { SIGINT, SIGABRT, 0 }; + static int sigerr[] = { SIG_FOR_TIMER, SIGSEGV, SIGFPE, SIGILL, SIGBUS, 0 }; + static int sigterm[] = { SIGINT, SIGABRT, SIGTERM, 0 }; return (install(on_signal_error, sigerr) & install(on_signal_terminate, sigterm)) - 1; } @@ -187,6 +210,3 @@ void sig_monitor(int timeout, void (*function)(int sig, void*), void *arg) } - - -