hush: explain why "pipe; exit $?" doesn't show correct exitcode
This commit is contained in:
parent
87cb2db703
commit
2f1bb36a55
@ -1,5 +1,10 @@
|
|||||||
Various bits of what is known about busybox shells, in no particular order.
|
Various bits of what is known about busybox shells, in no particular order.
|
||||||
|
|
||||||
|
2007-04-22
|
||||||
|
hush: "sleep 1 | exit 3; echo $?" prints 0 because $? is substituted
|
||||||
|
_before_ pipe gets executed!! run_list_real() already has "pipe;echo"
|
||||||
|
parsed and handed to it for execution, so it sees "pipe"; "echo 0".
|
||||||
|
|
||||||
2007-04-21
|
2007-04-21
|
||||||
hush: removed setsid() and made job control sort-of-sometimes-work.
|
hush: removed setsid() and made job control sort-of-sometimes-work.
|
||||||
Ctrl-C in "rm -i" works now except for SH_STANDALONE case.
|
Ctrl-C in "rm -i" works now except for SH_STANDALONE case.
|
||||||
|
28
shell/hush.c
28
shell/hush.c
@ -1541,7 +1541,7 @@ static int run_pipe_real(struct pipe *pi)
|
|||||||
|
|
||||||
pi->running_progs++;
|
pi->running_progs++;
|
||||||
|
|
||||||
/* Second and next children need to know ipd of first one */
|
/* Second and next children need to know pid of first one */
|
||||||
if (pi->pgrp < 0)
|
if (pi->pgrp < 0)
|
||||||
pi->pgrp = child->pid;
|
pi->pgrp = child->pid;
|
||||||
|
|
||||||
@ -1612,7 +1612,7 @@ static int run_list_real(struct pipe *pi)
|
|||||||
skip_more_in_this_rmode = RES_XXXX;
|
skip_more_in_this_rmode = RES_XXXX;
|
||||||
if (rmode == RES_THEN || rmode == RES_ELSE)
|
if (rmode == RES_THEN || rmode == RES_ELSE)
|
||||||
if_code = next_if_code;
|
if_code = next_if_code;
|
||||||
if (rmode == RES_THEN && if_code)
|
if (rmode == RES_THEN && if_code)
|
||||||
continue;
|
continue;
|
||||||
if (rmode == RES_ELSE && !if_code)
|
if (rmode == RES_ELSE && !if_code)
|
||||||
continue;
|
continue;
|
||||||
@ -2814,7 +2814,8 @@ static int parse_stream_outer(struct in_str *inp, int flag)
|
|||||||
ctx.type = flag;
|
ctx.type = flag;
|
||||||
initialize_context(&ctx);
|
initialize_context(&ctx);
|
||||||
update_ifs_map();
|
update_ifs_map();
|
||||||
if (!(flag & FLAG_PARSE_SEMICOLON) || (flag & FLAG_REPARSING)) mapset(";$&|", 0);
|
if (!(flag & FLAG_PARSE_SEMICOLON) || (flag & FLAG_REPARSING))
|
||||||
|
mapset(";$&|", 0);
|
||||||
inp->promptmode = 1;
|
inp->promptmode = 1;
|
||||||
rcode = parse_stream(&temp, &ctx, inp, '\n');
|
rcode = parse_stream(&temp, &ctx, inp, '\n');
|
||||||
if (rcode != 1 && ctx.old_flag != 0) {
|
if (rcode != 1 && ctx.old_flag != 0) {
|
||||||
@ -2832,7 +2833,7 @@ static int parse_stream_outer(struct in_str *inp, int flag)
|
|||||||
temp.nonnull = 0;
|
temp.nonnull = 0;
|
||||||
temp.quote = 0;
|
temp.quote = 0;
|
||||||
inp->p = NULL;
|
inp->p = NULL;
|
||||||
free_pipe_list(ctx.list_head,0);
|
free_pipe_list(ctx.list_head, 0);
|
||||||
}
|
}
|
||||||
b_free(&temp);
|
b_free(&temp);
|
||||||
} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */
|
} while (rcode != -1 && !(flag & FLAG_EXIT_FROM_LOOP)); /* loop on syntax errors, return on EOF */
|
||||||
@ -2862,6 +2863,8 @@ static void setup_job_control(void)
|
|||||||
{
|
{
|
||||||
pid_t shell_pgrp;
|
pid_t shell_pgrp;
|
||||||
|
|
||||||
|
saved_task_pgrp = getpgrp();
|
||||||
|
debug_printf("saved_task_pgrp=%d\n", saved_task_pgrp);
|
||||||
fcntl(interactive_fd, F_SETFD, FD_CLOEXEC);
|
fcntl(interactive_fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
|
||||||
/* Loop until we are in the foreground. */
|
/* Loop until we are in the foreground. */
|
||||||
@ -2952,7 +2955,9 @@ int hush_main(int argc, char **argv)
|
|||||||
opt = parse_string_outer(optarg, FLAG_PARSE_SEMICOLON);
|
opt = parse_string_outer(optarg, FLAG_PARSE_SEMICOLON);
|
||||||
goto final_return;
|
goto final_return;
|
||||||
case 'i':
|
case 'i':
|
||||||
/*interactive_fd++;*/ //huh??
|
// Well, we cannot just declare interactiveness,
|
||||||
|
// we have to have some stuff (ctty, etc)
|
||||||
|
/*interactive_fd++;*/
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
fake_mode++;
|
fake_mode++;
|
||||||
@ -2980,8 +2985,6 @@ int hush_main(int argc, char **argv)
|
|||||||
saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
|
saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
|
||||||
debug_printf("saved_tty_pgrp=%d\n", saved_tty_pgrp);
|
debug_printf("saved_tty_pgrp=%d\n", saved_tty_pgrp);
|
||||||
if (saved_tty_pgrp >= 0) {
|
if (saved_tty_pgrp >= 0) {
|
||||||
saved_task_pgrp = getpgrp();
|
|
||||||
debug_printf("saved_task_pgrp=%d\n", saved_task_pgrp);
|
|
||||||
/* try to dup to high fd#, >= 255 */
|
/* try to dup to high fd#, >= 255 */
|
||||||
interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
|
interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
|
||||||
if (interactive_fd < 0) {
|
if (interactive_fd < 0) {
|
||||||
@ -2991,17 +2994,14 @@ int hush_main(int argc, char **argv)
|
|||||||
/* give up */
|
/* give up */
|
||||||
interactive_fd = 0;
|
interactive_fd = 0;
|
||||||
}
|
}
|
||||||
|
// TODO: track & disallow any attempts of user
|
||||||
|
// to (inadvertently) close/redirect it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf("\ninteractive_fd=%d\n", interactive_fd);
|
debug_printf("\ninteractive_fd=%d\n", interactive_fd);
|
||||||
if (interactive_fd) {
|
if (interactive_fd) {
|
||||||
/* Looks like they want an interactive shell */
|
/* Looks like they want an interactive shell */
|
||||||
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
|
|
||||||
printf( "\n\n%s hush - the humble shell v0.01 (testing)\n",
|
|
||||||
BB_BANNER);
|
|
||||||
printf( "Enter 'help' for a list of built-in commands.\n\n");
|
|
||||||
#endif
|
|
||||||
setup_job_control();
|
setup_job_control();
|
||||||
/* Make xfuncs do cleanup on exit */
|
/* Make xfuncs do cleanup on exit */
|
||||||
die_sleep = -1; /* flag */
|
die_sleep = -1; /* flag */
|
||||||
@ -3009,6 +3009,10 @@ int hush_main(int argc, char **argv)
|
|||||||
/* xfunc has failed! die die die */
|
/* xfunc has failed! die die die */
|
||||||
hush_exit(xfunc_error_retval);
|
hush_exit(xfunc_error_retval);
|
||||||
}
|
}
|
||||||
|
#if !ENABLE_FEATURE_SH_EXTRA_QUIET
|
||||||
|
printf("\n\n%s hush - the humble shell v0.02\n", BB_BANNER);
|
||||||
|
printf("Enter 'help' for a list of built-in commands.\n\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[optind] == NULL) {
|
if (argv[optind] == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user