From: Eugene Syromyatnikov Date: Sun, 7 Oct 2018 03:23:09 +0000 (+0200) Subject: Use sprintsigname for converting signal number to string X-Git-Tag: v4.26~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63144af13f6433179c2603a2be5c2862fd4927a2;p=strace Use sprintsigname for converting signal number to string As signame is being converted to an xlookup-like function, a separate routine is needed in order to get string representation of signal. * defs.h (sprintsigname): New prototype. * signal.c (sprintsigname): New function. * strace.c (print_debug_info, print_signalled, print_stopped): Use it instead of signame. * wait.c (printstatus): Likewise. Co-Authored-by: Dmitry V. Levin --- diff --git a/defs.h b/defs.h index 15f84991..c9bca4ed 100644 --- a/defs.h +++ b/defs.h @@ -579,6 +579,7 @@ extern long getrval2(struct tcb *); #endif extern const char *signame(const int); +extern const char *sprintsigname(const int); extern void pathtrace_select_set(const char *, struct path_set *); extern bool pathtrace_match_set(struct tcb *, struct path_set *); diff --git a/signal.c b/signal.c index 5e23aa03..8dacd895 100644 --- a/signal.c +++ b/signal.c @@ -123,6 +123,21 @@ signame(const int sig) return buf; } +const char * +sprintsigname(const int sig) +{ + const char *str = signame(sig); + + if (str) + return str; + + static char buf[sizeof(sig) * 3 + 2]; + + xsprintf(buf, "%d", sig); + + return buf; +} + static unsigned int popcount32(const uint32_t *a, unsigned int size) { diff --git a/strace.c b/strace.c index 1ea74f93..e8e25161 100644 --- a/strace.c +++ b/strace.c @@ -1979,11 +1979,12 @@ print_debug_info(const int pid, int status) if (WIFSIGNALED(status)) xsprintf(buf, "WIFSIGNALED,%ssig=%s", WCOREDUMP(status) ? "core," : "", - signame(WTERMSIG(status))); + sprintsigname(WTERMSIG(status))); if (WIFEXITED(status)) xsprintf(buf, "WIFEXITED,exitcode=%u", WEXITSTATUS(status)); if (WIFSTOPPED(status)) - xsprintf(buf, "WIFSTOPPED,sig=%s", signame(WSTOPSIG(status))); + xsprintf(buf, "WIFSTOPPED,sig=%s", + sprintsigname(WSTOPSIG(status))); evbuf[0] = '\0'; if (event != 0) { static const char *const event_names[] = { @@ -2103,7 +2104,7 @@ print_signalled(struct tcb *tcp, const int pid, int status) && is_number_in_set(WTERMSIG(status), signal_set)) { printleader(tcp); tprintf("+++ killed by %s %s+++\n", - signame(WTERMSIG(status)), + sprintsigname(WTERMSIG(status)), WCOREDUMP(status) ? "(core dumped) " : ""); line_ended(); } @@ -2133,11 +2134,11 @@ print_stopped(struct tcb *tcp, const siginfo_t *si, const unsigned int sig) && is_number_in_set(sig, signal_set)) { printleader(tcp); if (si) { - tprintf("--- %s ", signame(sig)); + tprintf("--- %s ", sprintsigname(sig)); printsiginfo(si); tprints(" ---\n"); } else - tprintf("--- stopped by %s ---\n", signame(sig)); + tprintf("--- stopped by %s ---\n", sprintsigname(sig)); line_ended(); #ifdef ENABLE_STACKTRACE diff --git a/wait.c b/wait.c index 46c50aa9..dbc917b1 100644 --- a/wait.c +++ b/wait.c @@ -34,12 +34,12 @@ printstatus(int status) if (WIFSTOPPED(status)) { int sig = WSTOPSIG(status); tprintf("[{WIFSTOPPED(s) && WSTOPSIG(s) == %s%s}", - signame(sig & 0x7f), + sprintsigname(sig & 0x7f), sig & 0x80 ? " | 0x80" : ""); status &= ~W_STOPCODE(sig); } else if (WIFSIGNALED(status)) { tprintf("[{WIFSIGNALED(s) && WTERMSIG(s) == %s%s}", - signame(WTERMSIG(status)), + sprintsigname(WTERMSIG(status)), WCOREDUMP(status) ? " && WCOREDUMP(s)" : ""); status &= ~(W_EXITCODE(0, WTERMSIG(status)) | WCOREFLAG); } else if (WIFEXITED(status)) {