aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2010-04-02 13:59:42 +0800
committermaximilian attems <max@stro.at>2010-04-16 04:19:53 +0200
commit673dab8698b0399c967216c02262eaf95361a75c (patch)
tree08333fe9480e4e5a0b56b49ebb424cbf1bf35e03
parentdd99829df93e4666d4047548e1c9b085b2dd6b15 (diff)
downloadklibc-673dab8698b0399c967216c02262eaf95361a75c.tar.gz
[klibc] [BUILTIN] Make trap signal name/number errors non-fatal.
On Wed, Feb 24, 2010 at 10:23:34AM +0000, Peter Kjellerstedt wrote: > > there seems to be a problem with the trap implementation in dash > (tested with 0.5.4 and 0.5.5.1). If I specify a signal which is not > supported, the shell unconditionally aborts. E.g., I had expected > the following to print foo (like bash and zsh do): > > # dash -c 'trap "echo trap executed" UNKNOWNSIGNAL || echo "foo"' > trap: 1: UNKNOWNSIGNAL: bad trap > > This means I cannot write a construct like the following to take > advantage of the ERR signal which is present in some shells: > > trap "echo ERR trap executed" ERR 2>/dev/null || : > > I also checked the POSIX documentation, and quoting from > http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html > (exit status): "For both interactive and non-interactive shells, > invalid signal names [XSI] [Option Start] or numbers [Option End] > shall not be considered a syntax error and do not cause the shell > to abort." This patch replaces sh_error with a outfmt + return 1 in trapcmd so that these errors are no longer fatal. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/trap.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr/dash/trap.c b/usr/dash/trap.c
index e7a35d4aa0c20..18c3cd125c18b 100644
--- a/usr/dash/trap.c
+++ b/usr/dash/trap.c
@@ -116,8 +116,10 @@ trapcmd(int argc, char **argv)
else
action = *ap++;
while (*ap) {
- if ((signo = decode_signal(*ap, 0)) < 0)
- sh_error("%s: bad trap", *ap);
+ if ((signo = decode_signal(*ap, 0)) < 0) {
+ outfmt(out2, "trap: %s: bad trap\n", *ap);
+ return 1;
+ }
INTOFF;
if (action) {
if (action[0] == '-' && action[1] == '\0')