diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 20:06:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 20:06:17 +0200 |
commit | 86981e3ad2d03e77d1f668ac1603a041be448dae (patch) | |
tree | b7474eb7ce7117a4bcc883b5da97463dbbd952f6 | |
parent | f1a5cb0548f647e628032ea8645c0d0d2d07b02f (diff) | |
download | busybox-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>
-rw-r--r-- | libbb/u_signal_names.c | 2 | ||||
-rw-r--r-- | procps/kill.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 9 | ||||
-rw-r--r-- | shell/hush.c | 2 |
4 files changed, 10 insertions, 5 deletions
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index bf984a44e..b82a706d8 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -143,7 +143,7 @@ int FAST_FUNC get_signum(const char *name) | |||
143 | unsigned i; | 143 | unsigned i; |
144 | 144 | ||
145 | i = bb_strtou(name, NULL, 10); | 145 | i = bb_strtou(name, NULL, 10); |
146 | if (!errno) | 146 | if (!errno && i < NSIG) /* for shells, we allow 0 too */ |
147 | return i; | 147 | return i; |
148 | if (strncasecmp(name, "SIG", 3) == 0) | 148 | if (strncasecmp(name, "SIG", 3) == 0) |
149 | name += 3; | 149 | name += 3; |
diff --git a/procps/kill.c b/procps/kill.c index 5cff24475..09beefb2d 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -188,7 +188,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv) | |||
188 | arg = *++argv; | 188 | arg = *++argv; |
189 | } /* else it must be -SIG */ | 189 | } /* else it must be -SIG */ |
190 | signo = get_signum(arg); | 190 | signo = get_signum(arg); |
191 | if (signo < 0) { /* || signo > MAX_SIGNUM ? */ | 191 | if (signo < 0) { |
192 | bb_error_msg("bad signal name '%s'", arg); | 192 | bb_error_msg("bad signal name '%s'", arg); |
193 | return EXIT_FAILURE; | 193 | return EXIT_FAILURE; |
194 | } | 194 | } |
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; |
diff --git a/shell/hush.c b/shell/hush.c index f9dad074f..11b33f40a 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -9745,7 +9745,7 @@ static int FAST_FUNC builtin_trap(char **argv) | |||
9745 | sighandler_t handler; | 9745 | sighandler_t handler; |
9746 | 9746 | ||
9747 | sig = get_signum(*argv++); | 9747 | sig = get_signum(*argv++); |
9748 | if (sig < 0 || sig >= NSIG) { | 9748 | if (sig < 0) { |
9749 | ret = EXIT_FAILURE; | 9749 | ret = EXIT_FAILURE; |
9750 | /* Mimic bash message exactly */ | 9750 | /* Mimic bash message exactly */ |
9751 | bb_error_msg("trap: %s: invalid signal specification", argv[-1]); | 9751 | bb_error_msg("trap: %s: invalid signal specification", argv[-1]); |