diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-23 12:23:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-23 12:23:21 +0100 |
commit | 93e2a22482b72b3076377f71347e3dd07d7dd2f8 (patch) | |
tree | ebb6659c8bdfa1387b06e801feac06f17663b4ca | |
parent | 0ab2dd4f28bfcfc0a8043c6b30fba6dca806dcb9 (diff) | |
download | busybox-w32-93e2a22482b72b3076377f71347e3dd07d7dd2f8.tar.gz busybox-w32-93e2a22482b72b3076377f71347e3dd07d7dd2f8.tar.bz2 busybox-w32-93e2a22482b72b3076377f71347e3dd07d7dd2f8.zip |
shell: for signal exitcode, use 128 | sig, not 128 + sig - MIPS has signal 128
function old new delta
wait_for_child_or_signal 213 214 +1
refill_HFILE_and_getc 89 88 -1
getstatus 97 96 -1
builtin_wait 339 337 -2
checkjobs 187 183 -4
process_wait_result 450 444 -6
waitcmd 290 281 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 1/-23) Total: -22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 6 | ||||
-rw-r--r-- | shell/hush.c | 28 |
2 files changed, 18 insertions, 16 deletions
diff --git a/shell/ash.c b/shell/ash.c index f4d296289..aa2a93bca 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4610,7 +4610,7 @@ getstatus(struct job *job) | |||
4610 | job->sigint = 1; | 4610 | job->sigint = 1; |
4611 | #endif | 4611 | #endif |
4612 | } | 4612 | } |
4613 | retval += 128; | 4613 | retval |= 128; |
4614 | } | 4614 | } |
4615 | TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x\n", | 4615 | TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x\n", |
4616 | jobno(job), job->nprocs, status, retval)); | 4616 | jobno(job), job->nprocs, status, retval)); |
@@ -4676,7 +4676,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv) | |||
4676 | if (status != -1 && !WIFSTOPPED(status)) { | 4676 | if (status != -1 && !WIFSTOPPED(status)) { |
4677 | retval = WEXITSTATUS(status); | 4677 | retval = WEXITSTATUS(status); |
4678 | if (WIFSIGNALED(status)) | 4678 | if (WIFSIGNALED(status)) |
4679 | retval = WTERMSIG(status) + 128; | 4679 | retval = 128 | WTERMSIG(status); |
4680 | goto ret; | 4680 | goto ret; |
4681 | } | 4681 | } |
4682 | } | 4682 | } |
@@ -4711,7 +4711,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv) | |||
4711 | ret: | 4711 | ret: |
4712 | return retval; | 4712 | return retval; |
4713 | sigout: | 4713 | sigout: |
4714 | retval = 128 + pending_sig; | 4714 | retval = 128 | pending_sig; |
4715 | return retval; | 4715 | return retval; |
4716 | } | 4716 | } |
4717 | 4717 | ||
diff --git a/shell/hush.c b/shell/hush.c index dec5d544b..6b8f1c88c 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1656,12 +1656,12 @@ static int refill_HFILE_and_getc(HFILE *fp) | |||
1656 | return EOF; | 1656 | return EOF; |
1657 | } | 1657 | } |
1658 | /* Try to buffer more input */ | 1658 | /* Try to buffer more input */ |
1659 | fp->cur = fp->buf; | ||
1660 | n = safe_read(fp->fd, fp->buf, sizeof(fp->buf)); | 1659 | n = safe_read(fp->fd, fp->buf, sizeof(fp->buf)); |
1661 | if (n < 0) { | 1660 | if (n < 0) { |
1662 | bb_simple_perror_msg("read error"); | 1661 | bb_simple_perror_msg("read error"); |
1663 | n = 0; | 1662 | n = 0; |
1664 | } | 1663 | } |
1664 | fp->cur = fp->buf; | ||
1665 | fp->end = fp->buf + n; | 1665 | fp->end = fp->buf + n; |
1666 | if (n == 0) { | 1666 | if (n == 0) { |
1667 | /* EOF/error */ | 1667 | /* EOF/error */ |
@@ -2651,7 +2651,7 @@ static int get_user_input(struct in_str *i) | |||
2651 | /* ^C or SIGINT: return EOF */ | 2651 | /* ^C or SIGINT: return EOF */ |
2652 | /* bash prints ^C even on real SIGINT (non-kbd generated) */ | 2652 | /* bash prints ^C even on real SIGINT (non-kbd generated) */ |
2653 | write(STDOUT_FILENO, "^C\n", 3); | 2653 | write(STDOUT_FILENO, "^C\n", 3); |
2654 | G.last_exitcode = 128 + SIGINT; | 2654 | G.last_exitcode = 128 | SIGINT; |
2655 | i->p = NULL; | 2655 | i->p = NULL; |
2656 | i->peek_buf[0] = r = EOF; | 2656 | i->peek_buf[0] = r = EOF; |
2657 | return r; | 2657 | return r; |
@@ -2685,7 +2685,7 @@ static int get_user_input(struct in_str *i) | |||
2685 | */ | 2685 | */ |
2686 | check_and_run_traps(); | 2686 | check_and_run_traps(); |
2687 | if (G.flag_SIGINT) | 2687 | if (G.flag_SIGINT) |
2688 | G.last_exitcode = 128 + SIGINT; | 2688 | G.last_exitcode = 128 | SIGINT; |
2689 | if (r != '\0') | 2689 | if (r != '\0') |
2690 | break; | 2690 | break; |
2691 | } | 2691 | } |
@@ -8756,9 +8756,10 @@ static int process_wait_result(struct pipe *fg_pipe, pid_t childpid, int status) | |||
8756 | puts(sig == SIGINT || sig == SIGPIPE ? "" : strsignal(sig)); | 8756 | puts(sig == SIGINT || sig == SIGPIPE ? "" : strsignal(sig)); |
8757 | } | 8757 | } |
8758 | /* TODO: if (WCOREDUMP(status)) + " (core dumped)"; */ | 8758 | /* TODO: if (WCOREDUMP(status)) + " (core dumped)"; */ |
8759 | /* TODO: MIPS has 128 sigs (1..128), what if sig==128 here? | 8759 | /* MIPS has 128 sigs (1..128), if sig==128, |
8760 | * Maybe we need to use sig | 128? */ | 8760 | * 128 + sig would result in exitcode 256 -> 0! |
8761 | ex = sig + 128; | 8761 | */ |
8762 | ex = 128 | sig; | ||
8762 | } | 8763 | } |
8763 | fg_pipe->cmds[i].cmd_exitcode = ex; | 8764 | fg_pipe->cmds[i].cmd_exitcode = ex; |
8764 | } else { | 8765 | } else { |
@@ -8805,7 +8806,8 @@ static int process_wait_result(struct pipe *fg_pipe, pid_t childpid, int status) | |||
8805 | /* child exited */ | 8806 | /* child exited */ |
8806 | int rcode = WEXITSTATUS(status); | 8807 | int rcode = WEXITSTATUS(status); |
8807 | if (WIFSIGNALED(status)) | 8808 | if (WIFSIGNALED(status)) |
8808 | rcode = 128 + WTERMSIG(status); | 8809 | /* NB: not 128 + sig, MIPS has sig 128 */ |
8810 | rcode = 128 | WTERMSIG(status); | ||
8809 | pi->cmds[i].cmd_exitcode = rcode; | 8811 | pi->cmds[i].cmd_exitcode = rcode; |
8810 | if (G.last_bg_pid == pi->cmds[i].pid) | 8812 | if (G.last_bg_pid == pi->cmds[i].pid) |
8811 | G.last_bg_pid_exitcode = rcode; | 8813 | G.last_bg_pid_exitcode = rcode; |
@@ -8925,10 +8927,10 @@ static int checkjobs(struct pipe *fg_pipe, pid_t waitfor_pid) | |||
8925 | debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status); | 8927 | debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status); |
8926 | rcode = WEXITSTATUS(status); | 8928 | rcode = WEXITSTATUS(status); |
8927 | if (WIFSIGNALED(status)) | 8929 | if (WIFSIGNALED(status)) |
8928 | rcode = 128 + WTERMSIG(status); | 8930 | rcode = 128 | WTERMSIG(status); |
8929 | if (WIFSTOPPED(status)) | 8931 | if (WIFSTOPPED(status)) |
8930 | /* bash: "cmd & wait $!" and cmd stops: $? = 128 + stopsig */ | 8932 | /* bash: "cmd & wait $!" and cmd stops: $? = 128 | stopsig */ |
8931 | rcode = 128 + WSTOPSIG(status); | 8933 | rcode = 128 | WSTOPSIG(status); |
8932 | rcode++; | 8934 | rcode++; |
8933 | break; /* "wait PID" called us, give it exitcode+1 */ | 8935 | break; /* "wait PID" called us, give it exitcode+1 */ |
8934 | } | 8936 | } |
@@ -9318,7 +9320,7 @@ static NOINLINE int run_pipe(struct pipe *pi) | |||
9318 | * during builtin/nofork. | 9320 | * during builtin/nofork. |
9319 | */ | 9321 | */ |
9320 | if (sigismember(&G.pending_set, SIGINT)) | 9322 | if (sigismember(&G.pending_set, SIGINT)) |
9321 | rcode = 128 + SIGINT; | 9323 | rcode = 128 | SIGINT; |
9322 | } | 9324 | } |
9323 | free(argv_expanded); | 9325 | free(argv_expanded); |
9324 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) | 9326 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) |
@@ -11718,7 +11720,7 @@ static int wait_for_child_or_signal(struct pipe *waitfor_pipe, pid_t waitfor_pid | |||
11718 | sig = check_and_run_traps(); | 11720 | sig = check_and_run_traps(); |
11719 | if (sig /*&& sig != SIGCHLD - always true */) { | 11721 | if (sig /*&& sig != SIGCHLD - always true */) { |
11720 | /* Do this for any (non-ignored) signal, not only for ^C */ | 11722 | /* Do this for any (non-ignored) signal, not only for ^C */ |
11721 | ret = 128 + sig; | 11723 | ret = 128 | sig; |
11722 | break; | 11724 | break; |
11723 | } | 11725 | } |
11724 | /* SIGCHLD, or no signal, or ignored one, such as SIGQUIT. Repeat */ | 11726 | /* SIGCHLD, or no signal, or ignored one, such as SIGQUIT. Repeat */ |
@@ -11818,7 +11820,7 @@ static int FAST_FUNC builtin_wait(char **argv) | |||
11818 | process_wait_result(NULL, pid, status); | 11820 | process_wait_result(NULL, pid, status); |
11819 | ret = WEXITSTATUS(status); | 11821 | ret = WEXITSTATUS(status); |
11820 | if (WIFSIGNALED(status)) | 11822 | if (WIFSIGNALED(status)) |
11821 | ret = 128 + WTERMSIG(status); | 11823 | ret = 128 | WTERMSIG(status); |
11822 | } | 11824 | } |
11823 | } while (*++argv); | 11825 | } while (*++argv); |
11824 | 11826 | ||