diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-08-20 14:44:54 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-08-20 14:44:54 +0200 |
commit | df5d691c39b0ff41d3d98a01db078f7157eb0250 (patch) | |
tree | b5c0b57e97a9b7ea9f550c38441b5a7b65df79ed /src/log.c | |
parent | 841d770988e0856f7070e1897e8d244e476a999e (diff) | |
download | ofono-df5d691c39b0ff41d3d98a01db078f7157eb0250.tar.bz2 |
Add support for simple glibc based backtrace
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -23,8 +23,12 @@ #include <config.h> #endif +#define _GNU_SOURCE #include <stdarg.h> #include <syslog.h> +#include <stdlib.h> +#include <execinfo.h> +#include <dlfcn.h> #include "ofono.h" @@ -103,6 +107,49 @@ void ofono_debug(const char *format, ...) va_end(ap); } +static void signal_handler(int signo) +{ + void *frames[64]; + char **symbols; + size_t n_ptrs; + unsigned int i; + + n_ptrs = backtrace(frames, G_N_ELEMENTS(frames)); + symbols = backtrace_symbols(frames, n_ptrs); + if (symbols == NULL) { + ofono_error("No backtrace symbols"); + exit(1); + } + + ofono_error("Aborting (signal %d)", signo); + ofono_error("++++++++ backtrace ++++++++"); + + for (i = 1; i < n_ptrs; i++) + ofono_error("[%d]: %s", i - 1, symbols[i]); + + ofono_error("+++++++++++++++++++++++++++"); + + g_free(symbols); + exit(1); +} + +static void signal_setup(sighandler_t handler) +{ + struct sigaction sa; + sigset_t mask; + + sigemptyset(&mask); + sa.sa_handler = handler; + sa.sa_mask = mask; + sa.sa_flags = 0; + sigaction(SIGBUS, &sa, NULL); + sigaction(SIGILL, &sa, NULL); + sigaction(SIGFPE, &sa, NULL); + sigaction(SIGSEGV, &sa, NULL); + sigaction(SIGABRT, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); +} + extern struct ofono_debug_desc __start___debug[]; extern struct ofono_debug_desc __stop___debug[]; @@ -152,6 +199,8 @@ int __ofono_log_init(const char *debug, ofono_bool_t detach) if (detach == FALSE) option |= LOG_PERROR; + signal_setup(signal_handler); + openlog("ofonod", option, LOG_DAEMON); syslog(LOG_INFO, "oFono version %s", VERSION); @@ -165,5 +214,7 @@ void __ofono_log_cleanup(void) closelog(); + signal_setup(SIG_DFL); + g_strfreev(enabled); } |