summaryrefslogtreecommitdiff
path: root/common/cli_hush_upstream.c
diff options
context:
space:
mode:
authorFrancis Laniel <francis.laniel@amarulasolutions.com>2023-12-22 22:02:32 +0100
committerTom Rini <trini@konsulko.com>2023-12-28 12:02:56 -0500
commit9a068377313c1feabb55072d2d1157999cf9d15e (patch)
tree19502dfd7079f0c040ec2cb0a9efeedd3ee60cec /common/cli_hush_upstream.c
parent6bb39f5d16e8531eeca8237454cc528aa54c9e81 (diff)
cli: Enables using modern hush parser as command line parser
If one defines HUSH_MODERN_PARSER, it is then possible to use modern parser with: => cli get old => cli set modern => cli get modern Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Diffstat (limited to 'common/cli_hush_upstream.c')
-rw-r--r--common/cli_hush_upstream.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 3f2e4a54956..4b6ab20f3b1 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -7913,7 +7913,17 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger)
}
debug_print_tree(pipe_list, 0);
debug_printf_exec("parse_and_run_stream: run_and_free_list\n");
+#ifndef __U_BOOT__
run_and_free_list(pipe_list);
+#else /* __U_BOOT__ */
+ int rcode = run_and_free_list(pipe_list);
+ /*
+ * We reset input string to not run the following command, so running
+ * 'exit; echo foo' does not print foo.
+ */
+ if (rcode <= EXIT_RET_CODE)
+ setup_file_in_str(inp);
+#endif /* __U_BOOT__ */
empty = 0;
if (G_flag_return_in_progress == 1)
break;
@@ -10368,13 +10378,39 @@ static int run_list(struct pipe *pi)
#endif /* !__U_BOOT__ */
rcode = r = run_pipe(pi); /* NB: rcode is a smalluint, r is int */
#ifdef __U_BOOT__
- if (r == -2) {
- /* -2 indicates exit was called, so we need to quit now. */
- G.last_exitcode = rcode;
+ if (r <= EXIT_RET_CODE) {
+ int previous_rcode = G.last_exitcode;
+ /*
+ * This magic is to get the exit code given by the user.
+ * Contrary to old shell code, we use + EXIT_RET_CODE as EXIT_RET_CODE
+ * equals -2.
+ */
+ G.last_exitcode = -r + EXIT_RET_CODE;
- break;
+ /*
+ * This case deals with the following:
+ * => setenv inner 'echo entry inner; exit; echo inner done'
+ * => setenv outer 'echo entry outer; run inner; echo outer done'
+ * => run outer
+ * So, if we are in inner, we need to break and not run the other
+ * commands.
+ * Otherwise, we just continue in outer.
+ * As return code are propagated, we use the previous value to check if
+ * exit was just called or was propagated.
+ */
+ if (previous_rcode != r) {
+ /*
+ * If run from run_command, run_command_flags will be set, so we check
+ * this to know if we are in main input shell.
+ */
+ if (!G.run_command_flags)
+ printf("exit not allowed from main input shell.\n");
+
+ break;
+ }
+ continue;
}
-#endif
+#endif /* __U_BOOT__ */
if (r != -1) {
/* We ran a builtin, function, or group.
* rcode is already known