[klibc] [klibc:update-dash] [BUILTIN] Allow return in loop conditional to set exit status

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Thu Jan 24 19:15:19 PST 2019

Commit-ID:  fd669f4411c49513b030328ee8e85910db5bf1b8
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=fd669f4411c49513b030328ee8e85910db5bf1b8
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Mon, 6 Oct 2014 21:22:43 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000

[klibc] [BUILTIN] Allow return in loop conditional to set exit status


When return is used in a loop conditional the exit status will
be lost because we always set the exit status at the end of the
loop to that of the last command executed in the body.

This is counterintuitive and contrary to what most other shells do.

This patch fixes this by always preserving the exit status of
return when it is used in a loop conditional.

The patch was originally written by Gerrit Pape <pape at smarden.org>.

Reported-by: Stephane Chazelas <stephane_chazelas at yahoo.fr>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

 usr/dash/eval.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index bb106368..57db825b 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/eval.c
@@ -387,8 +387,9 @@ evalloop(union node *n, int flags)
 		status = exitstatus;
 		skip = skiploop();
 	} while (!(skip & ~SKIPCONT));
+	if (skip != SKIPFUNC)
+		exitstatus = status;
-	exitstatus = status;

More information about the klibc mailing list