]> granicus.if.org Git - strace/commitdiff
Use sprintsigname for converting signal number to string
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 7 Oct 2018 03:23:09 +0000 (05:23 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 17 Dec 2018 19:19:23 +0000 (19:19 +0000)
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 <ldv@altlinux.org>
defs.h
signal.c
strace.c
wait.c

diff --git a/defs.h b/defs.h
index 15f84991b48e7e63d6803a0e996916e2b4c5c25d..c9bca4ed3975f153cebac0044e0b019751d248d3 100644 (file)
--- 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 *);
 
index 5e23aa035f6c783e29ced0bd80352cd2f748267b..8dacd89543a89be507a98530e705d260770053c5 100644 (file)
--- 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)
 {
index 1ea74f93e91b7c53bace50a5602b83d1d8893dc8..e8e25161b51bd171ba65eed8f5cc10d76fcc45d5 100644 (file)
--- 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 46c50aa992675360f1889f6953725737b11fba6e..dbc917b1bb7cf4a15dd61bdbcd80f584d4310191 100644 (file)
--- 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)) {