diff mbox

[v3,15/17] eval: Fail immediately with redirections errors for simple command

Message ID E1fJkIE-0005px-1D@gondobar (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu May 18, 2018, 6:39 p.m. UTC
Previously, dash would continue to perform variable expansions
even if a redirection error occured.  This patch changes it so
that it fails immediately.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 src/eval.c |   36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/eval.c b/src/eval.c
index 22fe2d7..122613b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -818,6 +818,17 @@  evalcommand(union node *cmd, int flags)
 	redir_stop = pushredir(cmd->ncmd.redirect);
 	status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH|REDIR_SAVEFD2);
 
+	if (status) {
+bail:
+		exitstatus = status;
+
+		/* We have a redirection error. */
+		if (spclbltin > 0)
+			exraise(EXERROR);
+
+		goto out;
+	}
+
 	for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) {
 		struct strlist **spp;
 
@@ -848,30 +859,19 @@  evalcommand(union node *cmd, int flags)
 	    !(cmdentry.u.cmd->flags & BUILTIN_REGULAR)) {
 		find_command(argv[0], &cmdentry, cmd_flag | DO_ERR,
 			     unlikely(path) ? path : pathval());
-		if (cmdentry.cmdtype == CMDUNKNOWN) {
-			status = 127;
-#ifdef FLUSHERR
-			flushout(&errout);
-#endif
-			goto bail;
-		}
-	}
-
-	if (status) {
-bail:
-		exitstatus = status;
-
-		/* We have a redirection error. */
-		if (spclbltin > 0)
-			exraise(EXERROR);
-
-		goto out;
 	}
 
 	jp = NULL;
 
 	/* Execute the command. */
 	switch (cmdentry.cmdtype) {
+	case CMDUNKNOWN:
+		status = 127;
+#ifdef FLUSHERR
+		flushout(&errout);
+#endif
+		goto bail;
+
 	default:
 		/* Fork off a child process if necessary. */
 		if (!(flags & EV_EXIT) || have_traps()) {