diff options
author | Denys Vlasenko | 2017-07-25 20:06:17 +0200 |
---|---|---|
committer | Denys Vlasenko | 2017-07-25 20:06:17 +0200 |
commit | 86981e3ad2d03e77d1f668ac1603a041be448dae (patch) | |
tree | b7474eb7ce7117a4bcc883b5da97463dbbd952f6 /shell/ash.c | |
parent | f1a5cb0548f647e628032ea8645c0d0d2d07b02f (diff) | |
download | busybox-86981e3ad2d03e77d1f668ac1603a041be448dae.zip busybox-86981e3ad2d03e77d1f668ac1603a041be448dae.tar.gz |
ash: allow "trap NUM [SIG]..." syntax
While at it, make get_signum() return -1 for numeric strings >= NSIG.
function old new delta
trapcmd 292 306 +14
get_signum 295 300 +5
builtin_trap 413 412 -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 19/-1) Total: 18 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c index b4b0d52..42e14cb 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12981,13 +12981,18 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) return 0; } + /* Why the second check? + * "trap NUM [sig2]..." is the same as "trap - NUM [sig2]..." + * In this case, NUM is signal no, not an action. + */ action = NULL; - if (ap[1]) + if (ap[1] && !is_number(ap[0])) action = *ap++; + exitcode = 0; while (*ap) { signo = get_signum(*ap); - if (signo < 0 || signo >= NSIG) { + if (signo < 0) { /* Mimic bash message exactly */ ash_msg("%s: invalid signal specification", *ap); exitcode = 1; |