diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 15:52:24 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 15:52:24 +0100 |
commit | 496d5bf4c6566b7837e61fa83da3fb5851ae446b (patch) | |
tree | f91880f67012bccd6f3432e3bb4f34ec2a71cefc | |
parent | 19158a837df5093a2d655536424412bac2b07467 (diff) | |
download | busybox-w32-496d5bf4c6566b7837e61fa83da3fb5851ae446b.tar.gz busybox-w32-496d5bf4c6566b7837e61fa83da3fb5851ae446b.tar.bz2 busybox-w32-496d5bf4c6566b7837e61fa83da3fb5851ae446b.zip |
ash: trap with bad signal name should not abort
function old new delta
trapcmd 236 271 +35
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 14 | ||||
-rw-r--r-- | shell/ash_test/ash-signals/signal4.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-signals/signal4.tests | 5 |
3 files changed, 19 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c index e2851305b..0cfa4fc6f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -12281,7 +12281,7 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
12281 | { | 12281 | { |
12282 | char *action; | 12282 | char *action; |
12283 | char **ap; | 12283 | char **ap; |
12284 | int signo; | 12284 | int signo, exitcode; |
12285 | 12285 | ||
12286 | nextopt(nullstr); | 12286 | nextopt(nullstr); |
12287 | ap = argptr; | 12287 | ap = argptr; |
@@ -12314,10 +12314,15 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
12314 | action = NULL; | 12314 | action = NULL; |
12315 | if (ap[1]) | 12315 | if (ap[1]) |
12316 | action = *ap++; | 12316 | action = *ap++; |
12317 | exitcode = 0; | ||
12317 | while (*ap) { | 12318 | while (*ap) { |
12318 | signo = get_signum(*ap); | 12319 | signo = get_signum(*ap); |
12319 | if (signo < 0) | 12320 | if (signo < 0) { |
12320 | ash_msg_and_raise_error("%s: bad trap", *ap); | 12321 | /* Mimic bash message exactly */ |
12322 | ash_msg("%s: invalid signal specification", *ap); | ||
12323 | exitcode = 1; | ||
12324 | goto next; | ||
12325 | } | ||
12321 | INT_OFF; | 12326 | INT_OFF; |
12322 | if (action) { | 12327 | if (action) { |
12323 | if (LONE_DASH(action)) | 12328 | if (LONE_DASH(action)) |
@@ -12330,9 +12335,10 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
12330 | if (signo != 0) | 12335 | if (signo != 0) |
12331 | setsignal(signo); | 12336 | setsignal(signo); |
12332 | INT_ON; | 12337 | INT_ON; |
12338 | next: | ||
12333 | ap++; | 12339 | ap++; |
12334 | } | 12340 | } |
12335 | return 0; | 12341 | return exitcode; |
12336 | } | 12342 | } |
12337 | 12343 | ||
12338 | 12344 | ||
diff --git a/shell/ash_test/ash-signals/signal4.right b/shell/ash_test/ash-signals/signal4.right new file mode 100644 index 000000000..32605849c --- /dev/null +++ b/shell/ash_test/ash-signals/signal4.right | |||
@@ -0,0 +1,4 @@ | |||
1 | ./signal4.tests: trap: line 3: BADNAME: invalid signal specification | ||
2 | 1 | ||
3 | Trapped | ||
4 | Ok | ||
diff --git a/shell/ash_test/ash-signals/signal4.tests b/shell/ash_test/ash-signals/signal4.tests new file mode 100755 index 000000000..6f1c4a950 --- /dev/null +++ b/shell/ash_test/ash-signals/signal4.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | trap "echo Trapped" BADNAME TERM; echo $? | ||
4 | kill $$ | ||
5 | echo Ok | ||