From 40fe0d7e038b570a99f0e96ecc363f6186164d49 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 16 Dec 2008 16:35:56 -0800 Subject: [PATCH] Improve formatting of process termination messages in secchan logging. My expectation was that strsignal() returns the signal's name, e.g. SIGTERM. It actually returns an English explanation, so that the existing code would log a message like "terminated by signal Terminated". This commit changes the message to the more sensible "terminated by signal 15 (Terminated)". Also, the recently approved POSIX 2008 standardized strsignal() and in particular says that it may return NULL for unknown signal numbers, so this commit fixes the behavior on NULL return. --- secchan/executer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/secchan/executer.c b/secchan/executer.c index 5619c51ba..008d2cc1c 100644 --- a/secchan/executer.c +++ b/secchan/executer.c @@ -318,11 +318,14 @@ child_terminated(struct child *child, int status) if (WIFEXITED(status)) { ds_put_format(&ds, "normally with status %d", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { + const char *name = NULL; #ifdef HAVE_STRSIGNAL - ds_put_format(&ds, "by signal %s", strsignal(WTERMSIG(status))); -#else - ds_put_format(&ds, "by signal %d", WTERMSIG(status)); + name = strsignal(WTERMSIG(status)); #endif + ds_put_format(&ds, "by signal %d", WTERMSIG(status)); + if (name) { + ds_put_format(&ds, " (%s)", name); + } } if (WCOREDUMP(status)) { ds_put_cstr(&ds, " (core dumped)"); -- 2.43.0