From bcd7709452cdb6e25583cf808fb17984830f4528 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 25 Nov 2020 18:28:55 +0100 Subject: sgsn: 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: I65f70a53b6982bff9ea4bd6ff786d8a2f8181eac Fixes: OS#4865 --- src/sgsn/sgsn_main.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/sgsn/sgsn_main.c b/src/sgsn/sgsn_main.c index 1eccad8eb..e51336bf0 100644 --- a/src/sgsn/sgsn_main.c +++ b/src/sgsn/sgsn_main.c @@ -143,11 +143,11 @@ int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) return 0; } -static void signal_handler(int signal) +static void signal_handler(int signum) { - fprintf(stdout, "signal %u received\n", signal); + fprintf(stdout, "signal %u received\n", signum); - switch (signal) { + switch (signum) { case SIGINT: case SIGTERM: osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); @@ -155,8 +155,17 @@ static void signal_handler(int signal) exit(0); break; case SIGABRT: - /* in case of abort, we want to obtain a talloc report - * and then return to the caller, who will abort the process */ + /* 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(tall_vty_ctx, stderr); + talloc_report_full(tall_sgsn_ctx, stderr); + signal(SIGABRT, SIG_DFL); + raise(SIGABRT); + break; case SIGUSR1: talloc_report(tall_vty_ctx, stderr); talloc_report_full(tall_sgsn_ctx, stderr); -- cgit v1.2.3