diff --git a/common/string_calls.c b/common/string_calls.c index de74f9e5..14448bbf 100644 --- a/common/string_calls.c +++ b/common/string_calls.c @@ -422,6 +422,30 @@ g_atoi(const char *str) return atoi(str); } +/*****************************************************************************/ +char * +g_strsignal(int signum) +{ + char *result = strsignal(signum); + + if (result == NULL) + { + // Using a static buffer offers the same guarantees as the + // strsignal() call + static char buff[32]; + unsigned int len; + len = g_snprintf(buff, sizeof(buff), "SIG#%d", signum); + if (len >= sizeof(buff)) + { + // Buffer overflow + g_snprintf(buff, sizeof(buff), "SIG???"); + } + result = buff; + } + + return result; +} + /*****************************************************************************/ /* As g_atoi() but allows for hexadecimal too */ int diff --git a/common/string_calls.h b/common/string_calls.h index 49092c44..7403f11b 100644 --- a/common/string_calls.h +++ b/common/string_calls.h @@ -266,6 +266,12 @@ int g_strncmp_d(const char *c1, const char *c2, const char delim, int len); int g_strcasecmp(const char *c1, const char *c2); int g_strncasecmp(const char *c1, const char *c2, int len); int g_atoi(const char *str); +/** + * Implements POSIX 1003.1 strsignal() + * + * This function never returns NULL + */ +char *g_strsignal(int signum); /** * Extends g_atoi(), Converts decimal and hexadecimal number String to integer * diff --git a/sesman/sesexec/session.c b/sesman/sesexec/session.c index 485631d8..2385de68 100644 --- a/sesman/sesexec/session.c +++ b/sesman/sesexec/session.c @@ -821,7 +821,7 @@ exit_status_to_str(const struct exit_status *e, char buff[], int bufflen) break; case E_XR_SIGNAL: - g_snprintf(buff, bufflen, "signal %d", e->val); + g_snprintf(buff, bufflen, "signal \"%s\"", g_strsignal(e->val)); break; default: diff --git a/sesman/sesexec/xwait.c b/sesman/sesexec/xwait.c index 271804e6..375399ce 100644 --- a/sesman/sesexec/xwait.c +++ b/sesman/sesexec/xwait.c @@ -156,8 +156,8 @@ wait_for_xserver(uid_t uid, case E_XR_SIGNAL: LOG(LOG_LEVEL_ERROR, - "waitforx failed with unexpected signal %d", - e.val); + "waitforx failed with unexpected signal \"%s\"", + g_strsignal(e.val)); break; default: