trap: do not consider a bad signal name a fatal error.

POSIX explicitly prescribes this.
Continue processing any other signals and return status 1.
This commit is contained in:
Jilles Tjoelker 2009-11-21 20:44:34 +00:00
parent 80d5dd5fdb
commit e3c2cd7237
2 changed files with 18 additions and 3 deletions

View File

@ -149,6 +149,7 @@ trapcmd(int argc, char **argv)
{
char *action;
int signo;
int errors = 0;
if (argc <= 1) {
for (signo = 0 ; signo < sys_nsig ; signo++) {
@ -183,8 +184,10 @@ trapcmd(int argc, char **argv)
}
}
while (*argv) {
if ((signo = sigstring_to_signum(*argv)) == -1)
error("bad signal %s", *argv);
if ((signo = sigstring_to_signum(*argv)) == -1) {
out2fmt_flush("trap: bad signal %s\n", *argv);
errors = 1;
}
INTOFF;
if (action)
action = savestr(action);
@ -196,7 +199,7 @@ trapcmd(int argc, char **argv)
INTON;
argv++;
}
return 0;
return errors;
}

View File

@ -0,0 +1,12 @@
# $FreeBSD$
{
trap '' garbage && exit 3
trap - garbage && exit 3
trap true garbage && exit 3
trap '' 99999 && exit 3
trap - 99999 && exit 3
trap true 99999 && exit 3
} 2>/dev/null
test -n "$(trap true garbage TERM 2>/dev/null || trap)" || exit 3
exit 0