Check Ctrl-C status before executing each command in the pipeline so that the Ctrl-C can skip all subsequent commands. This should be the default behavior of most shells.
Before the change: ``` => echo start; while true; do echo loop; sleep 1; done; echo int; if true; then echo if; fi; echo stop start loop loop <-- Input Ctrl-C int if stop => ``` After the change: ``` => echo start; while true; do echo loop; sleep 1; done; echo int; if true; then echo if; fi; echo stop start loop loop <-- Input Ctrl-C ^C => ``` Signed-off-by: Shiji Yang <[email protected]> --- common/cli_hush.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/cli_hush.c b/common/cli_hush.c index 7bd6943d3ed..6757a94a454 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -1792,16 +1792,15 @@ static int run_list_real(struct pipe *pi) } } for (; pi; pi = (flag_restore != 0) ? rpipe : pi->next) { - if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL || - pi->r_mode == RES_FOR) { #ifdef __U_BOOT__ - /* check Ctrl-C */ - ctrlc(); - if ((had_ctrlc())) { - return 1; - } + /* check Ctrl-C */ + ctrlc(); + if (had_ctrlc()) + return 1; #endif - flag_restore = 0; + if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL || + pi->r_mode == RES_FOR) { + flag_restore = 0; if (!rpipe) { flag_rep = 0; rpipe = pi; @@ -2024,6 +2023,12 @@ static int run_list(struct pipe *pi) * In the long run that function can be merged with run_list_real, * but doing that now would hobble the debugging effort. */ free_pipe_list(pi,0); + + if (had_ctrlc()) { + printf("^C\n"); + clear_ctrlc(); + } + return rcode; } -- 2.51.0

