diff --git a/bin/sh/trap.c b/bin/sh/trap.c index f00c6d516cab..23f1885af4d5 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -89,6 +89,8 @@ static int getsigaction(int, sig_t *); /* * Map a string to a signal number. + * + * Note: the signal number may exceed NSIG. */ static int sigstring_to_signum(char *sig) @@ -120,14 +122,24 @@ sigstring_to_signum(char *sig) static void printsignals(void) { - int n; + int n, outlen; + outlen = 0; for (n = 1; n < sys_nsig; n++) { - out1fmt("%s", sys_signame[n]); - if (n == (NSIG / 2) || n == (NSIG - 1)) + if (sys_signame[n]) { + out1fmt("%s", sys_signame[n]); + outlen += strlen(sys_signame[n]); + } else { + out1fmt("%d", n); + outlen += 3; /* good enough */ + } + ++outlen; + if (outlen > 70 || n == sys_nsig - 1) { out1str("\n"); - else + outlen = 0; + } else { out1c(' '); + } } } @@ -143,9 +155,18 @@ trapcmd(int argc, char **argv) if (argc <= 1) { for (signo = 0 ; signo < sys_nsig ; signo++) { - if (trap[signo] != NULL) - out1fmt("trap -- '%s' %s\n", trap[signo], - (signo) ? sys_signame[signo] : "exit"); + if (signo < NSIG && trap[signo] != NULL) { + if (signo == 0) { + out1fmt("trap -- '%s' %s\n", + trap[signo], "exit"); + } else if (sys_signame[signo]) { + out1fmt("trap -- '%s' %s\n", + trap[signo], sys_signame[signo]); + } else { + out1fmt("trap -- '%s' %d\n", + trap[signo], signo); + } + } } return 0; }