From d75300bfa58d8a70a02b8d00c349d2c643eff45a Mon Sep 17 00:00:00 2001 From: Alfred Perlstein Date: Sat, 17 Jul 2004 19:19:36 +0000 Subject: [PATCH] When reporting reciept of a signal, print the signal's name. --- usr.bin/truss/extern.h | 1 + usr.bin/truss/main.c | 24 +++++++++++++++++++++++- usr.bin/truss/syscalls.c | 8 ++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/usr.bin/truss/extern.h b/usr.bin/truss/extern.h index 0a1355e5e312..ee977fbd8c3f 100644 --- a/usr.bin/truss/extern.h +++ b/usr.bin/truss/extern.h @@ -35,6 +35,7 @@ extern int setup_and_wait(char **); extern int start_tracing(int, int, int); extern void restore_proc(int); extern const char *ioctlname(register_t val); +extern char *strsig(int sig); #ifdef __alpha__ extern void alpha_syscall_entry(struct trussinfo *, int); extern long alpha_syscall_exit(struct trussinfo *, int); diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index f1939c19c8cc..8822d9ed32b3 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -138,6 +139,23 @@ set_etype(struct trussinfo *trussinfo) { return funcs; } +char * +strsig(int sig) +{ + char *ret; + + ret = NULL; + if (sig > 0 && sig < NSIG) { + int i; + asprintf(&ret, "sig%s", sys_signame[sig]); + if (ret == NULL) + return (NULL); + for (i = 0; ret[i] != '\0'; ++i) + ret[i] = toupper(ret[i]); + } + return (ret); +} + int main(int ac, char **av) { int c; @@ -149,6 +167,7 @@ main(int ac, char **av) { char *fname = NULL; int sigexit = 0; struct trussinfo *trussinfo; + char *signame; /* Initialize the trussinfo struct */ trussinfo = (struct trussinfo *)malloc(sizeof(struct trussinfo)); @@ -285,7 +304,10 @@ main(int ac, char **av) { funcs->exit_syscall(trussinfo, pfs.val); break; case S_SIG: - fprintf(trussinfo->outfile, "SIGNAL %lu\n", pfs.val); + signame = strsig(pfs.val); + fprintf(trussinfo->outfile, "SIGNAL %lu (%s)\n", pfs.val, + signame == NULL ? "?" : signame); + free(signame); sigexit = pfs.val; break; case S_EXIT: diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index fff0555aeed4..992f94fa820e 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -471,12 +471,8 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) { long sig; sig = args[sc->offset]; - if (sig > 0 && sig < NSIG) { - int i; - asprintf(&tmp, "sig%s", sys_signame[sig]); - for (i = 0; tmp[i] != '\0'; ++i) - tmp[i] = toupper(tmp[i]); - } else + tmp = strsig(sig); + if (tmp == NULL) asprintf(&tmp, "%ld", sig); } break;