From efb88bf5ffe5aa1a8116ee118ef9104e4afc3873 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 25 Nov 2020 18:43:10 +0100 Subject: trxcon: 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: I6d80f3f2742d397e47f4f2970c951f2cf6d58172 Fixes: OS#4865 --- src/host/trxcon/trxcon.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/host/trxcon/trxcon.c b/src/host/trxcon/trxcon.c index e14e2c90..158e27f7 100644 --- a/src/host/trxcon/trxcon.c +++ b/src/host/trxcon/trxcon.c @@ -241,15 +241,25 @@ static void init_defaults(void) app_data.quit = 0; } -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: app_data.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_trxcon_ctx, stderr); + signal(SIGABRT, SIG_DFL); + raise(SIGABRT); + break; case SIGUSR1: case SIGUSR2: talloc_report_full(tall_trxcon_ctx, stderr); -- cgit v1.2.3