From: Jonathan Perkin <jperkin@joyent.com>
To: dash@vger.kernel.org
Subject: [PATCH] trap: Implement POSIX.1-2008 trap reset behaviour (#2)
Date: Mon, 7 Dec 2015 17:50:47 +0000 [thread overview]
Message-ID: <20151207175047.GG735@joyent.com> (raw)
Clarifies a couple of issues with the previous patch, and expands on
the rationale in the commit message. Sorry for the noise -- jperkin
POSIX.1-2008 for trap adds the following behaviour:
If the first operand is an unsigned decimal integer, the shell shall
treat all operands as conditions, and shall reset each condition to
the default value.
The interpretation of this behaviour differs among other shells. In the
case where the first operand is an invalid signo:
bash-4.3.39(1), zsh-5.1.1:
$ trap echo 1 2 3
$ trap 100 1 2
$ trap
trap -- '100' SIGHUP
trap -- '100' SIGINT
trap -- 'echo' SIGQUIT
mksh-51:
$ trap echo 1 2 3
$ trap 100 1 2
mksh: trap: bad signal '100'
$ trap
trap -- echo QUIT
ksh 93u+:
$ trap echo 1 2 3
$ trap 100 1 2
ksh: trap: 100: bad trap
$ trap
trap -- echo QUIT
trap -- echo INT
trap -- echo HUP
As the standard does not appear to specify that the first operand must
be a valid signo for this behaviour to be triggered, we align with the
ksh behaviour:
$ trap echo 1 2 3
$ trap 100 1 2
trap: 100: bad trap
$ trap
trap -- 'echo' HUP
trap -- 'echo' INT
trap -- 'echo' QUIT
As for the case of the first operand being a signal name:
bash-4.3.39(1), mksh-51, ksh 93u+:
$ trap echo 1 2 3
$ trap HUP 2
$ trap
trap -- 'echo' SIGHUP
trap -- 'HUP' SIGINT
trap -- 'echo' SIGQUIT
zsh-5.1.1:
$ trap echo 1 2 3
$ trap HUP 2
$ trap
trap -- echo QUIT
Here we go with the majority and a strict interpretation of the
standard, parsing it as a string rather than a signal:
$ trap echo 1 2 3
$ trap HUP 2
$ trap
trap -- 'echo' HUP
trap -- 'HUP' INT
trap -- 'echo' QUIT
---
src/trap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/trap.c b/src/trap.c
index 82d4263..3dc1949 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -112,7 +112,7 @@ trapcmd(int argc, char **argv)
}
return 0;
}
- if (!ap[1])
+ if ((!ap[1]) || (is_number(*ap)))
action = NULL;
else
action = *ap++;
--
2.4.9 (Apple Git-60)
--
Jonathan Perkin - Joyent, Inc. - www.joyent.com
next reply other threads:[~2015-12-07 17:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 17:50 Jonathan Perkin [this message]
2015-12-08 8:24 ` [PATCH] trap: Implement POSIX.1-2008 trap reset behaviour (#2) Herbert Xu
2015-12-08 9:51 ` Jonathan Perkin
2016-06-06 11:52 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151207175047.GG735@joyent.com \
--to=jperkin@joyent.com \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).