All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cli_hush: fix 'exit' cmd that was not exiting scripts
@ 2022-11-18 11:19 Hector Palacios
  2022-11-19 14:12 ` Marek Vasut
  0 siblings, 1 reply; 5+ messages in thread
From: Hector Palacios @ 2022-11-18 11:19 UTC (permalink / raw)
  To: u-boot; +Cc: marex, festevam, Adrian Vovk

Commit 8c4e3b79bd0bb76eea16869e9666e19047c0d005 supposedly
passed one-level up the argument passed to 'exit' but it also
broke 'exit' purpose of stopping a script.

In reality, even if 'do_exit()' is capable of returning any
integer, the cli only admits '1' or '0' as return values.

This commit respects the current implementation to allow 'exit'
to at least return '1' for future processing, but returns
when the command being run is 'exit'.

Before this:

	=> setenv foo 'echo bar ; exit 3 ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0
	=> setenv foo 'echo bar ; exit 1 ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0
	=> setenv foo 'echo bar ; exit 0 ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0
	=> setenv foo 'echo bar ; exit -1 ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0
	=> setenv foo 'echo bar ; exit -2 ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0
	=> setenv foo 'echo bar ; exit ; echo should not see this'; run foo; echo $?
	bar
	should not see this
	0

After this:

        => setenv foo 'echo bar ; exit 3 ; echo should not see this'; run foo; echo $?
        bar
        1
        => setenv foo 'echo bar ; exit 1 ; echo should not see this'; run foo; echo $?
        bar
        1
        => setenv foo 'echo bar ; exit 0 ; echo should not see this'; run foo; echo $?
        bar
        0
        => setenv foo 'echo bar ; exit -1 ; echo should not see this'; run foo; echo $?
        bar
        0
        => setenv foo 'echo bar ; exit -2 ; echo should not see this'; run foo; echo $?
        bar
        0
        => setenv foo 'echo bar ; exit ; echo should not see this'; run foo; echo $?
        bar
        0

Reported-by: Adrian Vovk <avovk@cc-sw.com>
Signed-off-by: Hector Palacios <hector.palacios@digi.com>
---
 common/cli_hush.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/cli_hush.c b/common/cli_hush.c
index 1467ff81b35b..9fe8b87e02d7 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -1902,6 +1902,10 @@ static int run_list_real(struct pipe *pi)
 			last_return_code = -rcode - 2;
 			return -2;	/* exit */
 		}
+		if (!strcmp(pi->progs->argv[0], "exit")) {
+			last_return_code = rcode;
+			return rcode;   /* exit */
+		}
 		last_return_code=(rcode == 0) ? 0 : 1;
 #endif
 #ifndef __U_BOOT__

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-25 21:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18 11:19 [PATCH] cli_hush: fix 'exit' cmd that was not exiting scripts Hector Palacios
2022-11-19 14:12 ` Marek Vasut
2022-11-21  8:55   ` Hector Palacios
2022-11-21 16:32     ` Hector Palacios
2022-11-25 21:35       ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.