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>
This commit is contained in:
parent
0ab2dd4f28
commit
93e2a22482
@ -4610,7 +4610,7 @@ getstatus(struct job *job)
|
|||||||
job->sigint = 1;
|
job->sigint = 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
retval += 128;
|
retval |= 128;
|
||||||
}
|
}
|
||||||
TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x\n",
|
TRACE(("getstatus: job %d, nproc %d, status 0x%x, retval 0x%x\n",
|
||||||
jobno(job), job->nprocs, status, retval));
|
jobno(job), job->nprocs, status, retval));
|
||||||
@ -4676,7 +4676,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (status != -1 && !WIFSTOPPED(status)) {
|
if (status != -1 && !WIFSTOPPED(status)) {
|
||||||
retval = WEXITSTATUS(status);
|
retval = WEXITSTATUS(status);
|
||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
retval = WTERMSIG(status) + 128;
|
retval = 128 | WTERMSIG(status);
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4711,7 +4711,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
ret:
|
ret:
|
||||||
return retval;
|
return retval;
|
||||||
sigout:
|
sigout:
|
||||||
retval = 128 + pending_sig;
|
retval = 128 | pending_sig;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
shell/hush.c
28
shell/hush.c
@ -1656,12 +1656,12 @@ static int refill_HFILE_and_getc(HFILE *fp)
|
|||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
/* Try to buffer more input */
|
/* Try to buffer more input */
|
||||||
fp->cur = fp->buf;
|
|
||||||
n = safe_read(fp->fd, fp->buf, sizeof(fp->buf));
|
n = safe_read(fp->fd, fp->buf, sizeof(fp->buf));
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
bb_simple_perror_msg("read error");
|
bb_simple_perror_msg("read error");
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
fp->cur = fp->buf;
|
||||||
fp->end = fp->buf + n;
|
fp->end = fp->buf + n;
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
/* EOF/error */
|
/* EOF/error */
|
||||||
@ -2651,7 +2651,7 @@ static int get_user_input(struct in_str *i)
|
|||||||
/* ^C or SIGINT: return EOF */
|
/* ^C or SIGINT: return EOF */
|
||||||
/* bash prints ^C even on real SIGINT (non-kbd generated) */
|
/* bash prints ^C even on real SIGINT (non-kbd generated) */
|
||||||
write(STDOUT_FILENO, "^C\n", 3);
|
write(STDOUT_FILENO, "^C\n", 3);
|
||||||
G.last_exitcode = 128 + SIGINT;
|
G.last_exitcode = 128 | SIGINT;
|
||||||
i->p = NULL;
|
i->p = NULL;
|
||||||
i->peek_buf[0] = r = EOF;
|
i->peek_buf[0] = r = EOF;
|
||||||
return r;
|
return r;
|
||||||
@ -2685,7 +2685,7 @@ static int get_user_input(struct in_str *i)
|
|||||||
*/
|
*/
|
||||||
check_and_run_traps();
|
check_and_run_traps();
|
||||||
if (G.flag_SIGINT)
|
if (G.flag_SIGINT)
|
||||||
G.last_exitcode = 128 + SIGINT;
|
G.last_exitcode = 128 | SIGINT;
|
||||||
if (r != '\0')
|
if (r != '\0')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -8756,9 +8756,10 @@ static int process_wait_result(struct pipe *fg_pipe, pid_t childpid, int status)
|
|||||||
puts(sig == SIGINT || sig == SIGPIPE ? "" : strsignal(sig));
|
puts(sig == SIGINT || sig == SIGPIPE ? "" : strsignal(sig));
|
||||||
}
|
}
|
||||||
/* TODO: if (WCOREDUMP(status)) + " (core dumped)"; */
|
/* TODO: if (WCOREDUMP(status)) + " (core dumped)"; */
|
||||||
/* TODO: MIPS has 128 sigs (1..128), what if sig==128 here?
|
/* MIPS has 128 sigs (1..128), if sig==128,
|
||||||
* Maybe we need to use sig | 128? */
|
* 128 + sig would result in exitcode 256 -> 0!
|
||||||
ex = sig + 128;
|
*/
|
||||||
|
ex = 128 | sig;
|
||||||
}
|
}
|
||||||
fg_pipe->cmds[i].cmd_exitcode = ex;
|
fg_pipe->cmds[i].cmd_exitcode = ex;
|
||||||
} else {
|
} else {
|
||||||
@ -8805,7 +8806,8 @@ static int process_wait_result(struct pipe *fg_pipe, pid_t childpid, int status)
|
|||||||
/* child exited */
|
/* child exited */
|
||||||
int rcode = WEXITSTATUS(status);
|
int rcode = WEXITSTATUS(status);
|
||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
rcode = 128 + WTERMSIG(status);
|
/* NB: not 128 + sig, MIPS has sig 128 */
|
||||||
|
rcode = 128 | WTERMSIG(status);
|
||||||
pi->cmds[i].cmd_exitcode = rcode;
|
pi->cmds[i].cmd_exitcode = rcode;
|
||||||
if (G.last_bg_pid == pi->cmds[i].pid)
|
if (G.last_bg_pid == pi->cmds[i].pid)
|
||||||
G.last_bg_pid_exitcode = rcode;
|
G.last_bg_pid_exitcode = rcode;
|
||||||
@ -8925,10 +8927,10 @@ static int checkjobs(struct pipe *fg_pipe, pid_t waitfor_pid)
|
|||||||
debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status);
|
debug_printf_exec("childpid==waitfor_pid:%d status:0x%08x\n", childpid, status);
|
||||||
rcode = WEXITSTATUS(status);
|
rcode = WEXITSTATUS(status);
|
||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
rcode = 128 + WTERMSIG(status);
|
rcode = 128 | WTERMSIG(status);
|
||||||
if (WIFSTOPPED(status))
|
if (WIFSTOPPED(status))
|
||||||
/* bash: "cmd & wait $!" and cmd stops: $? = 128 + stopsig */
|
/* bash: "cmd & wait $!" and cmd stops: $? = 128 | stopsig */
|
||||||
rcode = 128 + WSTOPSIG(status);
|
rcode = 128 | WSTOPSIG(status);
|
||||||
rcode++;
|
rcode++;
|
||||||
break; /* "wait PID" called us, give it exitcode+1 */
|
break; /* "wait PID" called us, give it exitcode+1 */
|
||||||
}
|
}
|
||||||
@ -9318,7 +9320,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
|
|||||||
* during builtin/nofork.
|
* during builtin/nofork.
|
||||||
*/
|
*/
|
||||||
if (sigismember(&G.pending_set, SIGINT))
|
if (sigismember(&G.pending_set, SIGINT))
|
||||||
rcode = 128 + SIGINT;
|
rcode = 128 | SIGINT;
|
||||||
}
|
}
|
||||||
free(argv_expanded);
|
free(argv_expanded);
|
||||||
IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
|
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
|
|||||||
sig = check_and_run_traps();
|
sig = check_and_run_traps();
|
||||||
if (sig /*&& sig != SIGCHLD - always true */) {
|
if (sig /*&& sig != SIGCHLD - always true */) {
|
||||||
/* Do this for any (non-ignored) signal, not only for ^C */
|
/* Do this for any (non-ignored) signal, not only for ^C */
|
||||||
ret = 128 + sig;
|
ret = 128 | sig;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* SIGCHLD, or no signal, or ignored one, such as SIGQUIT. Repeat */
|
/* SIGCHLD, or no signal, or ignored one, such as SIGQUIT. Repeat */
|
||||||
@ -11818,7 +11820,7 @@ static int FAST_FUNC builtin_wait(char **argv)
|
|||||||
process_wait_result(NULL, pid, status);
|
process_wait_result(NULL, pid, status);
|
||||||
ret = WEXITSTATUS(status);
|
ret = WEXITSTATUS(status);
|
||||||
if (WIFSIGNALED(status))
|
if (WIFSIGNALED(status))
|
||||||
ret = 128 + WTERMSIG(status);
|
ret = 128 | WTERMSIG(status);
|
||||||
}
|
}
|
||||||
} while (*++argv);
|
} while (*++argv);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user