aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-11-25 19:03:35 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2020-11-25 19:03:35 +0100
commit48ffeb8139cf520a365fb0c2b98f37229791bed0 (patch)
tree022bb2af06b148bfe629972a50fb76803e3cb8f2
parent251fc3c06c50518f278d0102a22fefd212ed79ea (diff)
common: generate coredump and exit upon SIGABRT received
Previous code relied on abort() switching sigaction to SIG_FDL + retriggering SIGABRT in case the signal handler returns, which would then generate the coredump + terminate the process. However, if a SIGABRT is received from somewhere else (kill -SIGABRT), then the process would print the talloc report and continue running, which is not desired. Change-Id: Ic3b7c223046a80b51f0bd70ef1b15e12e6487ad0 Fixes: OS#4865
-rw-r--r--src/common/main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/common/main.c b/src/common/main.c
index f75e096a..16ffd1e0 100644
--- a/src/common/main.c
+++ b/src/common/main.c
@@ -214,11 +214,11 @@ static void handle_options(int argc, char **argv)
/* FIXME: remove this once we add multi-BTS support */
struct gsm_bts *g_bts = NULL;
-static void signal_handler(int signal)
+static void signal_handler(int signum)
{
- fprintf(stderr, "signal %u received\n", signal);
+ fprintf(stderr, "signal %u received\n", signum);
- switch (signal) {
+ switch (signum) {
case SIGINT:
case SIGTERM:
if (!quit) {
@@ -230,6 +230,16 @@ static void signal_handler(int signal)
quit++;
break;
case SIGABRT:
+ /* in case of abort, we want to obtain a talloc report and
+ * then run default SIGABRT handler, who will generate coredump
+ * and abort the process. abort() should do this for us after we
+ * return, but program wouldn't exit if an external SIGABRT is
+ * received.
+ */
+ talloc_report_full(tall_bts_ctx, stderr);
+ signal(SIGABRT, SIG_DFL);
+ raise(SIGABRT);
+ break;
case SIGUSR1:
case SIGUSR2:
talloc_report_full(tall_bts_ctx, stderr);