summaryrefslogtreecommitdiff
path: root/common/cli.c
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2022-12-20 07:25:59 +0100
committerTom Rini <trini@konsulko.com>2023-01-11 15:02:24 -0500
commit721307eba0e7d94241698936c58352ee3c6da748 (patch)
tree7252c2fc1aad94b0c013ac8e092d40dac2093623 /common/cli.c
parentf3d914cfdd5ac611d99f04096497f4cd13dd6aaa (diff)
downloadu-boot-721307eba0e7d94241698936c58352ee3c6da748.tar.gz
u-boot-721307eba0e7d94241698936c58352ee3c6da748.tar.bz2
u-boot-721307eba0e7d94241698936c58352ee3c6da748.zip
cmd: exit: Fix return value propagation out of environment scripts
Make sure the 'exit' command as well as 'exit $val' command exits from environment scripts immediately and propagates return value out of those scripts fully. That means the following behavior is expected: " => setenv foo 'echo bar ; exit 1' ; run foo ; echo $? bar 1 => setenv foo 'echo bar ; exit 0' ; run foo ; echo $? bar 0 => setenv foo 'echo bar ; exit -2' ; run foo ; echo $? bar 0 " As well as the followin behavior: " => setenv foo 'echo bar ; exit 3 ; echo fail'; run foo; echo $? bar 3 => setenv foo 'echo bar ; exit 1 ; echo fail'; run foo; echo $? bar 1 => setenv foo 'echo bar ; exit 0 ; echo fail'; run foo; echo $? bar 0 => setenv foo 'echo bar ; exit -1 ; echo fail'; run foo; echo $? bar 0 => setenv foo 'echo bar ; exit -2 ; echo fail'; run foo; echo $? bar 0 => setenv foo 'echo bar ; exit ; echo fail'; run foo; echo $? bar 0 " Fixes: 8c4e3b79bd0 ("cmd: exit: Fix return value") Reviewed-by: Hector Palacios <hector.palacios@digi.com> Signed-off-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'common/cli.c')
-rw-r--r--common/cli.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/common/cli.c b/common/cli.c
index a47d6a3f2b..ba45dad2db 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -146,7 +146,7 @@ int run_commandf(const char *fmt, ...)
#if defined(CONFIG_CMD_RUN)
int do_run(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
- int i;
+ int i, ret;
if (argc < 2)
return CMD_RET_USAGE;
@@ -160,8 +160,9 @@ int do_run(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return 1;
}
- if (run_command(arg, flag | CMD_FLAG_ENV) != 0)
- return 1;
+ ret = run_command(arg, flag | CMD_FLAG_ENV);
+ if (ret)
+ return ret;
}
return 0;
}