diff options
author | Marek Vasut <marex@denx.de> | 2022-12-20 09:25:59 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-11 23:02:24 +0300 |
commit | 721307eba0e7d94241698936c58352ee3c6da748 (patch) | |
tree | 7252c2fc1aad94b0c013ac8e092d40dac2093623 /cmd | |
parent | f3d914cfdd5ac611d99f04096497f4cd13dd6aaa (diff) | |
download | u-boot-721307eba0e7d94241698936c58352ee3c6da748.tar.xz |
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 'cmd')
-rw-r--r-- | cmd/exit.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/cmd/exit.c b/cmd/exit.c index 2c7132693a..7bf241ec73 100644 --- a/cmd/exit.c +++ b/cmd/exit.c @@ -10,10 +10,13 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + int r; + + r = 0; if (argc > 1) - return dectoul(argv[1], NULL); + r = simple_strtoul(argv[1], NULL, 10); - return 0; + return -r - 2; } U_BOOT_CMD( |