X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fsig-monitor.c;h=fbc5b1fb503dc918cb0517669394bf6a16205238;hb=a63851bb4726c89d9a3c5755d78d1c4bbc3f3b2e;hp=d00f0f974b9e46af24d91abc35e5a38ad20b9b8a;hpb=feccdb76f572a5fad947475c21b5b9aff696b04b;p=src%2Fapp-framework-binder.git diff --git a/src/sig-monitor.c b/src/sig-monitor.c index d00f0f97..fbc5b1fb 100644 --- a/src/sig-monitor.c +++ b/src/sig-monitor.c @@ -24,10 +24,13 @@ #include #include #include +#include #include "sig-monitor.h" #include "verbose.h" +#define SIG_FOR_TIMER SIGVTALRM + /* local handler */ static _Thread_local sigjmp_buf *error_handler; @@ -35,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 * @@ -49,7 +72,7 @@ static inline int timeout_create() rc = 0; else { sevp.sigev_notify = SIGEV_THREAD_ID; - sevp.sigev_signo = SIGALRM; + sevp.sigev_signo = SIG_FOR_TIMER; sevp.sigev_value.sival_ptr = NULL; #if defined(sigev_notify_thread_id) sevp.sigev_notify_thread_id = (pid_t)syscall(SYS_gettid); @@ -107,6 +130,8 @@ static inline void timeout_delete() static void on_signal_terminate (int signum) { ERROR("Terminating signal %d received: %s", signum, strsignal(signum)); + if (signum == SIGABRT) + dumpstack(3); exit(1); } @@ -115,6 +140,12 @@ 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) { sigemptyset(&sigset); @@ -122,8 +153,6 @@ static void on_signal_error(int signum) sigprocmask(SIG_UNBLOCK, &sigset, 0); longjmp(*error_handler, signum); } - if (signum == SIGALRM) - return; ERROR("Unmonitored signal %d received: %s", signum, strsignal(signum)); exit(2); } @@ -144,8 +173,8 @@ static int install(void (*handler)(int), int *signals) int sig_monitor_init() { - static int sigerr[] = { SIGALRM, 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; } @@ -161,16 +190,6 @@ void sig_monitor_clean_timeouts() } void sig_monitor(int timeout, void (*function)(int sig, void*), void *arg) -{ - sig_monitor3(timeout, (void (*)(int,void*,void*,void*))function, arg, NULL, NULL); -} - -void sig_monitor2(int timeout, void (*function)(int sig, void*, void*), void *arg1, void *arg2) -{ - sig_monitor3(timeout, (void (*)(int,void*,void*,void*))function, arg1, arg2, NULL); -} - -void sig_monitor3(int timeout, void (*function)(int sig, void*, void*, void*), void *arg1, void *arg2, void *arg3) { volatile int signum, signum2; sigjmp_buf jmpbuf, *older; @@ -181,11 +200,11 @@ void sig_monitor3(int timeout, void (*function)(int sig, void*, void*, void*), v error_handler = &jmpbuf; if (timeout) timeout_arm(timeout); - function(0, arg1, arg2, arg3); + function(0, arg); } else { signum2 = setjmp(jmpbuf); if (signum2 == 0) - function(signum, arg1, arg2, arg3); + function(signum, arg); } error_handler = older; if (timeout) @@ -193,6 +212,3 @@ void sig_monitor3(int timeout, void (*function)(int sig, void*, void*, void*), v } - - -