From ce780fc9e6067b15b65ca2904c698c77503bf635 Mon Sep 17 00:00:00 2001 From: Nate Sammons Date: Mon, 29 Mar 1999 23:23:13 +0000 Subject: [PATCH] Add new function `signame', which returns name (SIGXXX) of numeric signal, and replace lookups in signalent[] with calls to it. --- defs.h | 1 + process.c | 4 ++-- signal.c | 41 ++++++++++++++++++++++++++++++----------- strace.c | 8 ++++---- syscall.c | 2 +- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/defs.h b/defs.h index d9ecccca..4dcef209 100644 --- 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 *)); diff --git a/process.c b/process.c index bcea3d48..388ab97f 100644 --- 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]", diff --git a/signal.c b/signal.c index 5860bf9c..c52c8deb 100644 --- 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; } diff --git a/strace.c b/strace.c index 5b23f810..3af52353 100644 --- 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); } diff --git a/syscall.c b/syscall.c index 3d9ee95b..70e516ea 100644 --- 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; -- 2.40.0