]> granicus.if.org Git - strace/commitdiff
Add new function `signame', which returns name (SIGXXX) of numeric
authorNate Sammons <nate@users.sourceforge.net>
Mon, 29 Mar 1999 23:23:13 +0000 (23:23 +0000)
committerNate Sammons <nate@users.sourceforge.net>
Mon, 29 Mar 1999 23:23:13 +0000 (23:23 +0000)
signal, and replace lookups in signalent[] with calls to it.

defs.h
process.c
signal.c
strace.c
syscall.c

diff --git a/defs.h b/defs.h
index d9ecccca47fe510ed991f07835ba8f554b79a237..4dcef2090ec9bec77da7470800738852969308b2 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -267,6 +267,7 @@ extern int clearbpt P((struct tcb *));
 extern int setbpt P((struct tcb *));
 extern int sigishandled P((struct tcb *, int));
 extern void printcall P((struct tcb *));
+extern char *signame P((int));
 extern void printsignal P((int));
 extern void printleader P((struct tcb *));
 extern void printtrailer P((struct tcb *));
index bcea3d48b2858e830120ca6d1d2254e9df9d9884..388ab97fdf84c4578c1adee55c4fbfec0179c55e 100644 (file)
--- a/process.c
+++ b/process.c
@@ -890,10 +890,10 @@ int status;
         */
        if (WIFSTOPPED(status))
                tprintf("[WIFSTOPPED(s) && WSTOPSIG(s) == %s]",
-                       signalent[WSTOPSIG(status)]);
+                       signame(WSTOPSIG(status)));
        else if WIFSIGNALED(status)
                tprintf("[WIFSIGNALED(s) && WTERMSIG(s) == %s%s]",
-                       signalent[WTERMSIG(status)],
+                       signame(WTERMSIG(status)),
                        WCOREDUMP(status) ? " && WCOREDUMP(s)" : "");
        else if WIFEXITED(status) {
                tprintf("[WIFEXITED(s) && WEXITSTATUS(s) == %d]",
index 5860bf9c38560e0651c57c94d14cf466a088db8d..c52c8deb3624b4bcc97b29683279375a52f744a0 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -197,6 +197,33 @@ static struct xlat sigprocmaskcmds[] = {
 
 #endif /* HAVE_SIGACTION */
 
+/* Anonymous realtime signals. */
+/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
+   constant.  This is what we want.  Otherwise, just use SIGRTMIN. */
+#ifdef SIGRTMIN
+#ifndef __SIGRTMIN
+#define __SIGRTMIN SIGRTMIN
+#define __SIGRTMAX SIGRTMAX /* likewise */
+#endif
+#endif
+
+char *
+signame(sig)
+int sig;
+{
+       static char buf[30];
+       if (sig < nsignals) {
+               return signalent[sig];
+#ifdef SIGRTMIN
+       } else if (sig <= __SIGRTMIN && sig <= __SIGRTMAX) {
+               sprintf(buf, "SIGRT_%d", sig);
+               return buf;
+#endif /* SIGRTMIN */
+       } else {
+               sprintf(buf, "%d", sig);
+               return buf;
+       }
+}
 
 static char *
 sprintsigmask(s, mask)
@@ -231,7 +258,7 @@ sigset_t *mask;
        *s++ = '[';
        for (i = 1; i < nsignals; i++) {
                if (sigismember(mask, i) == 1) {
-                       sprintf(s, format, signalent[i] + 3); s += strlen(s);
+                       sprintf(s, format, signame(i) + 3); s += strlen(s);
                        format = " %s";
                }
        }
@@ -251,10 +278,7 @@ void
 printsignal(nr)
 int nr;
 {
-       if (nr > 0 && nr < nsignals)
-               tprintf("%s", signalent[nr]);
-       else
-               tprintf("%d", nr);
+       tprintf(signame(nr));
 }
 
 /*
@@ -1027,12 +1051,7 @@ sys_kill(tcp)
 struct tcb *tcp;
 {
        if (entering(tcp)) {
-               long sig = tcp->u_arg[1];
-
-               if (sig >= 0 && sig < NSIG)
-                       tprintf("%ld, %s", tcp->u_arg[0], signalent[sig]);
-               else
-                       tprintf("%ld, %ld", tcp->u_arg[0], sig);
+               tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
        }
        return 0;
 }
index 5b23f810da5691ff1075f544edd0864ff49a8b5d..3af523532c2566043298de41700131185394673e 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -1314,7 +1314,7 @@ trace()
                        if (!cflag && (qual_flags[what] & QUAL_SIGNAL)) {
                                printleader(tcp);
                                tprintf("--- %s (%s) ---",
-                                       signalent[what], strsignal(what));
+                                       signame(what), strsignal(what));
                                printtrailer(tcp);
                        }
                        break;
@@ -1426,7 +1426,7 @@ trace()
                            && (qual_flags[WTERMSIG(status)] & QUAL_SIGNAL)) {
                                printleader(tcp);
                                tprintf("+++ killed by %s +++",
-                                       signalent[WTERMSIG(status)]);
+                                       signame(WTERMSIG(status)));
                                printtrailer(tcp);
                        }
                        droptcb(tcp);
@@ -1449,7 +1449,7 @@ trace()
                }
                if (debug)
                        fprintf(stderr, "pid %u stopped, [%s]\n",
-                               pid, signalent[WSTOPSIG(status)]);
+                               pid, signame(WSTOPSIG(status)));
 
                if (tcp->flags & TCB_STARTUP) {
                        /*
@@ -1509,7 +1509,7 @@ trace()
                            && (qual_flags[WSTOPSIG(status)] & QUAL_SIGNAL)) {
                                printleader(tcp);
                                tprintf("--- %s (%s) ---",
-                                       signalent[WSTOPSIG(status)],
+                                       signame(WSTOPSIG(status)),
                                        strsignal(WSTOPSIG(status)));
                                printtrailer(tcp);
                        }
index 3d9ee95bc005c2d0ff647a38111a351477d6ca4d..70e516ea811916b65d67a66d94553b860a052f6f 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -252,7 +252,7 @@ char *s;
        if (strncmp(s, "SIG", 3) == 0)
                s += 3;
        for (i = 0; i <= NSIG; i++) {
-               if (strcmp(s, signalent[i] + 3) == 0)
+               if (strcmp(s, signame(i) + 3) == 0)
                        return i;
        }
        return -1;