aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-04 11:37:09 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-04 11:37:09 +0100
commita4899efd03d2fdaaf3f581d89a7a4844832d3fbb (patch)
tree8fab20ee4e6503866945de3bb400eadf9618b7ac
parent4168fdd8e6f5ad4d41a30a2350dbd635cc0fa6e1 (diff)
downloadbusybox-w32-a4899efd03d2fdaaf3f581d89a7a4844832d3fbb.tar.gz
busybox-w32-a4899efd03d2fdaaf3f581d89a7a4844832d3fbb.tar.bz2
busybox-w32-a4899efd03d2fdaaf3f581d89a7a4844832d3fbb.zip
hush: fix exitcodes of killed processes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c6
-rw-r--r--shell/hush_test/hush-misc/sig_exitcode.right5
-rwxr-xr-xshell/hush_test/hush-misc/sig_exitcode.tests9
3 files changed, 18 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 3044024a0..25094654d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3896,9 +3896,7 @@ static int checkjobs(struct pipe* fg_pipe)
3896 fg_pipe->alive_cmds--; 3896 fg_pipe->alive_cmds--;
3897 if (i == fg_pipe->num_cmds - 1) { 3897 if (i == fg_pipe->num_cmds - 1) {
3898 /* last process gives overall exitstatus */ 3898 /* last process gives overall exitstatus */
3899 /* Note: is WIFSIGNALED, WEXITSTATUS = sig + 128 */
3900 rcode = WEXITSTATUS(status); 3899 rcode = WEXITSTATUS(status);
3901 IF_HAS_KEYWORDS(if (fg_pipe->pi_inverted) rcode = !rcode;)
3902 /* bash prints killer signal's name for *last* 3900 /* bash prints killer signal's name for *last*
3903 * process in pipe (prints just newline for SIGINT). 3901 * process in pipe (prints just newline for SIGINT).
3904 * Mimic this. Example: "sleep 5" + (^\ or kill -QUIT) 3902 * Mimic this. Example: "sleep 5" + (^\ or kill -QUIT)
@@ -3906,7 +3904,11 @@ static int checkjobs(struct pipe* fg_pipe)
3906 if (WIFSIGNALED(status)) { 3904 if (WIFSIGNALED(status)) {
3907 int sig = WTERMSIG(status); 3905 int sig = WTERMSIG(status);
3908 printf("%s\n", sig == SIGINT ? "" : get_signame(sig)); 3906 printf("%s\n", sig == SIGINT ? "" : get_signame(sig));
3907 /* TODO: MIPS has 128 sigs (1..128), what if sig==128 here?
3908 * Maybe we need to use sig | 128? */
3909 rcode = sig + 128;
3909 } 3910 }
3911 IF_HAS_KEYWORDS(if (fg_pipe->pi_inverted) rcode = !rcode;)
3910 } 3912 }
3911 } else { 3913 } else {
3912 fg_pipe->cmds[i].is_stopped = 1; 3914 fg_pipe->cmds[i].is_stopped = 1;
diff --git a/shell/hush_test/hush-misc/sig_exitcode.right b/shell/hush_test/hush-misc/sig_exitcode.right
new file mode 100644
index 000000000..d5f000a08
--- /dev/null
+++ b/shell/hush_test/hush-misc/sig_exitcode.right
@@ -0,0 +1,5 @@
1KILL
2137:137
3KILL
40:0
5Done
diff --git a/shell/hush_test/hush-misc/sig_exitcode.tests b/shell/hush_test/hush-misc/sig_exitcode.tests
new file mode 100755
index 000000000..7879dc854
--- /dev/null
+++ b/shell/hush_test/hush-misc/sig_exitcode.tests
@@ -0,0 +1,9 @@
1exec 2>&1
2
3$THIS_SH -c 'kill -9 $$'
4echo 137:$?
5
6! $THIS_SH -c 'kill -9 $$'
7echo 0:$?
8
9echo Done