aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-25 20:06:17 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-25 20:06:17 +0200
commit86981e3ad2d03e77d1f668ac1603a041be448dae (patch)
treeb7474eb7ce7117a4bcc883b5da97463dbbd952f6 /shell/ash.c
parentf1a5cb0548f647e628032ea8645c0d0d2d07b02f (diff)
downloadbusybox-w32-86981e3ad2d03e77d1f668ac1603a041be448dae.tar.gz
busybox-w32-86981e3ad2d03e77d1f668ac1603a041be448dae.tar.bz2
busybox-w32-86981e3ad2d03e77d1f668ac1603a041be448dae.zip
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.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b4b0d5253..42e14cbc8 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12981,13 +12981,18 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12981 return 0; 12981 return 0;
12982 } 12982 }
12983 12983
12984 /* Why the second check?
12985 * "trap NUM [sig2]..." is the same as "trap - NUM [sig2]..."
12986 * In this case, NUM is signal no, not an action.
12987 */
12984 action = NULL; 12988 action = NULL;
12985 if (ap[1]) 12989 if (ap[1] && !is_number(ap[0]))
12986 action = *ap++; 12990 action = *ap++;
12991
12987 exitcode = 0; 12992 exitcode = 0;
12988 while (*ap) { 12993 while (*ap) {
12989 signo = get_signum(*ap); 12994 signo = get_signum(*ap);
12990 if (signo < 0 || signo >= NSIG) { 12995 if (signo < 0) {
12991 /* Mimic bash message exactly */ 12996 /* Mimic bash message exactly */
12992 ash_msg("%s: invalid signal specification", *ap); 12997 ash_msg("%s: invalid signal specification", *ap);
12993 exitcode = 1; 12998 exitcode = 1;