From a137c6a8534e395b486d910661496f3c02b6ec2a Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 21 Sep 2021 16:02:48 +0200 Subject: [PATCH] TT#142600 Improve signal handling On signals that are expected to terminate the program gracefully, do not call abort, otherwise we get core dumps for conditions, that while unexpected are not worth a core dump, such timing out when called with the timeout program. Print the signal name instead of number Change-Id: I740978882288801d71d4d3c4a1bbbde8b70e6a4f --- dhtest.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dhtest.c b/dhtest.c index f8f6b8e..9b8d202 100644 --- a/dhtest.c +++ b/dhtest.c @@ -111,8 +111,13 @@ static void cleanup(void) { } static void sigcleanup(int sig) { + fprintf(stderr, "signal %s received, exiting\n", strsignal(sig)); + cleanup(); +} + +static void sigabort(int sig) { signal(SIGABRT, SIG_DFL); - fprintf(stderr, "signal %i received, aborting\n", sig); + fprintf(stderr, "signal %s received, aborting\n", strsignal(sig)); cleanup(); abort(); } @@ -130,8 +135,8 @@ int main(int argc, char *argv[]) init_rand(); atexit(cleanup); - signal(SIGSEGV, sigcleanup); - signal(SIGABRT, sigcleanup); + signal(SIGSEGV, sigabort); + signal(SIGABRT, sigabort); signal(SIGTERM, sigcleanup); signal(SIGINT, sigcleanup); signal(SIGHUP, sigcleanup);