Module Name:    src
Committed By:   martin
Date:           Sat Aug 25 14:22:50 UTC 2018

Modified Files:
        src/bin/sh [netbsd-8]: eval.c eval.h main.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #983):

        bin/sh/eval.c: revision 1.158
        bin/sh/eval.h: revision 1.21
        bin/sh/main.c: revision 1.74

PR bin/48875

Revert the changes that were made 19 May 2016 (principally eval.c 1.125)
and the bug fixes in subsequent days (eval.c 1.126 and 1.127) and also
update some newer code that was added more recently which acted in
accordance with those changes (make that code be as it would have been
if the changes now being reverted had never been made).

While the changes made did solve the problem, in a sense, they were
never correct (see the PR for some discussion) and it had always been
intended that they be reverted.   However, in practical sh code, no
issues were reported - until just recently - so nothing was done,
until now...

After this commit, the validate_fn_redirects test case of the sh ATF
test t_redir will fail.   In particular, the subtest of that test
case which is described in the source (of the test) as:

        This one is the real test for PR bin/48875

will fail.

Alternative changes, not to "fix" the problem in the PR, but to
often avoid it will be coming very soon - after which that ATF
test will succeed again.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.140.2.4 -r1.140.2.5 src/bin/sh/eval.c
cvs rdiff -u -r1.19 -r1.19.8.1 src/bin/sh/eval.h
cvs rdiff -u -r1.70.2.1 -r1.70.2.2 src/bin/sh/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.140.2.4 src/bin/sh/eval.c:1.140.2.5
--- src/bin/sh/eval.c:1.140.2.4	Sat Aug 25 11:45:40 2018
+++ src/bin/sh/eval.c	Sat Aug 25 14:22:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $	*/
+/*	$NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $");
+__RCSID("$NetBSD: eval.c,v 1.140.2.5 2018/08/25 14:22:49 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -221,7 +221,7 @@ evalstring(char *s, int flag)
 	while ((n = parsecmd(0)) != NEOF) {
 		XTRACE(DBG_EVAL, ("evalstring: "), showtree(n));
 		if (n && nflag == 0)
-			evaltree(n, flag | EV_MORE);
+			evaltree(n, flag);
 		popstackmark(&smark);
 	}
 	popfile();
@@ -256,20 +256,19 @@ evaltree(union node *n, int flags)
 	    getpid(), n, NODETYPENAME(n->type), n->type, flags));
 	switch (n->type) {
 	case NSEMI:
-		evaltree(n->nbinary.ch1, (sflags & EV_TESTED) |
-		    (n->nbinary.ch2 ? EV_MORE : 0));
+		evaltree(n->nbinary.ch1, flags & EV_TESTED);
 		if (nflag || evalskip)
 			goto out;
 		evaltree(n->nbinary.ch2, flags);
 		break;
 	case NAND:
-		evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
+		evaltree(n->nbinary.ch1, EV_TESTED);
 		if (nflag || evalskip || exitstatus != 0)
 			goto out;
 		evaltree(n->nbinary.ch2, flags);
 		break;
 	case NOR:
-		evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
+		evaltree(n->nbinary.ch1, EV_TESTED);
 		if (nflag || evalskip || exitstatus == 0)
 			goto out;
 		evaltree(n->nbinary.ch2, flags);
@@ -296,14 +295,14 @@ evaltree(union node *n, int flags)
 		}
 		break;
 	case NSUBSHELL:
-		evalsubshell(n, flags & ~EV_MORE);
+		evalsubshell(n, flags);
 		do_etest = !(flags & EV_TESTED);
 		break;
 	case NBACKGND:
-		evalsubshell(n, flags & ~EV_MORE);
+		evalsubshell(n, flags);
 		break;
 	case NIF: {
-		evaltree(n->nif.test, EV_TESTED | EV_MORE);
+		evaltree(n->nif.test, EV_TESTED);
 		if (nflag || evalskip)
 			goto out;
 		if (exitstatus == 0)
@@ -331,11 +330,11 @@ evaltree(union node *n, int flags)
 		exitstatus = 0;
 		break;
 	case NNOT:
-		evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
+		evaltree(n->nnot.com, EV_TESTED);
 		exitstatus = !exitstatus;
 		break;
 	case NDNOT:
-		evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
+		evaltree(n->nnot.com, EV_TESTED);
 		if (exitstatus != 0)
 			exitstatus = 1;
 		break;
@@ -379,7 +378,7 @@ evalloop(union node *n, int flags)
 	CTRACE(DBG_EVAL,  ("\n"));
 
 	for (;;) {
-		evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
+		evaltree(n->nbinary.ch1, EV_TESTED);
 		if (nflag)
 			break;
 		if (evalskip) {
@@ -398,7 +397,7 @@ evalloop(union node *n, int flags)
 			if (exitstatus == 0)
 				break;
 		}
-		evaltree(n->nbinary.ch2, (flags & EV_TESTED) | EV_MORE);
+		evaltree(n->nbinary.ch2, flags & EV_TESTED);
 		status = exitstatus;
 		if (evalskip)
 			goto skipping;
@@ -431,11 +430,6 @@ evalfor(union node *n, int flags)
 
 	loopnest++;
 	for (sp = arglist.list ; sp ; sp = sp->next) {
-		int f = flags & (EV_TESTED | EV_MORE);
-
-		if (sp->next)
-			f |= EV_MORE;
-
 		if (xflag) {
 			out2str(expandstr(ps4val(), line_number));
 			out2str("for ");
@@ -447,7 +441,7 @@ evalfor(union node *n, int flags)
 		}
 
 		setvar(n->nfor.var, sp->text, 0);
-		evaltree(n->nfor.body, f);
+		evaltree(n->nfor.body, flags & EV_TESTED);
 		status = exitstatus;
 		if (nflag)
 			break;
@@ -493,8 +487,7 @@ evalcase(union node *n, int flags)
 					else
 						ncp = NULL;
 					line_number = cp->nclist.lineno;
-					evaltree(cp->nclist.body,
-					    ncp ? (flags | EV_MORE) : flags);
+					evaltree(cp->nclist.body, flags);
 					status = exitstatus;
 					cp = ncp;
 				}
@@ -965,8 +958,6 @@ evalcommand(union node *cmd, int flgs, s
 		INTOFF;
 		jp = makejob(cmd, 1);
 		mode = cmd->ncmd.backgnd;
-		if (mode)
-			flags &= ~EV_MORE;
 		if (flags & EV_BACKCMD) {
 			mode = FORK_NOJOB;
 			if (sh_pipe(pip) < 0)
@@ -1068,6 +1059,7 @@ evalcommand(union node *cmd, int flgs, s
 	case CMDFUNCTION:
 		VXTRACE(DBG_EVAL, ("Shell function:  "), trargs(argv));
 		redirect(cmd->ncmd.redirect, flags & EV_MORE ? REDIR_PUSH : 0);
+		redirect(cmd->ncmd.redirect, REDIR_PUSH);
 		saveparam = shellparam;
 		shellparam.malloc = 0;
 		shellparam.reset = 1;
@@ -1126,8 +1118,7 @@ evalcommand(union node *cmd, int flgs, s
 		freeparam(&shellparam);
 		shellparam = saveparam;
 		handler = savehandler;
-		if (flags & EV_MORE)
-			popredir();
+		popredir();
 		INTON;
 		if (evalskip == SKIPFUNC) {
 			evalskip = SKIPNONE;

Index: src/bin/sh/eval.h
diff -u src/bin/sh/eval.h:1.19 src/bin/sh/eval.h:1.19.8.1
--- src/bin/sh/eval.h:1.19	Mon May  9 21:03:10 2016
+++ src/bin/sh/eval.h	Sat Aug 25 14:22:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.h,v 1.19 2016/05/09 21:03:10 kre Exp $	*/
+/*	$NetBSD: eval.h,v 1.19.8.1 2018/08/25 14:22:49 martin Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -76,4 +76,3 @@ void reset_eval(void);
 #define EV_EXIT		0x01	/* exit after evaluating tree */
 #define EV_TESTED	0x02	/* exit status is checked; ignore -e flag */
 #define EV_BACKCMD	0x04	/* command executing within back quotes */
-#define EV_MORE		0x08	/* more commands in this sub-shell */

Index: src/bin/sh/main.c
diff -u src/bin/sh/main.c:1.70.2.1 src/bin/sh/main.c:1.70.2.2
--- src/bin/sh/main.c:1.70.2.1	Sun Jul 23 14:58:14 2017
+++ src/bin/sh/main.c	Sat Aug 25 14:22:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.70.2.1 2017/07/23 14:58:14 snj Exp $	*/
+/*	$NetBSD: main.c,v 1.70.2.2 2018/08/25 14:22:49 martin Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.7 (Berkeley) 7/19/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.70.2.1 2017/07/23 14:58:14 snj Exp $");
+__RCSID("$NetBSD: main.c,v 1.70.2.2 2018/08/25 14:22:49 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -292,7 +292,7 @@ cmdloop(int top)
 		} else if (n != NULL && nflag == 0) {
 			job_warning = (job_warning == 2) ? 1 : 0;
 			numeof = 0;
-			evaltree(n, EV_MORE);
+			evaltree(n, 0);
 		}
 		popstackmark(&smark);
 		setstackmark(&smark);

Reply via email to