Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Mar 2010 17:31:10 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r204802 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201003061731.o26HVA5F089437@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Mar  6 17:31:09 2010
New Revision: 204802
URL: http://svn.freebsd.org/changeset/base/204802

Log:
  sh: Make sure to popredir() even if a function caused an error.

Added:
  head/tools/regression/bin/sh/builtins/command10.0   (contents, props changed)
Modified:
  head/bin/sh/eval.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c	Sat Mar  6 17:09:22 2010	(r204801)
+++ head/bin/sh/eval.c	Sat Mar  6 17:31:09 2010	(r204802)
@@ -813,7 +813,6 @@ evalcommand(union node *cmd, int flags, 
 #ifdef DEBUG
 		trputs("Shell function:  ");  trargs(argv);
 #endif
-		redirect(cmd->ncmd.redirect, REDIR_PUSH);
 		saveparam = shellparam;
 		shellparam.malloc = 0;
 		shellparam.reset = 1;
@@ -831,6 +830,8 @@ evalcommand(union node *cmd, int flags, 
 			else {
 				freeparam(&shellparam);
 				shellparam = saveparam;
+				if (exception == EXERROR || exception == EXEXEC)
+					popredir();
 			}
 			unreffunc(cmdentry.u.func);
 			poplocalvars();
@@ -841,6 +842,7 @@ evalcommand(union node *cmd, int flags, 
 		}
 		handler = &jmploc;
 		funcnest++;
+		redirect(cmd->ncmd.redirect, REDIR_PUSH);
 		INTON;
 		for (sp = varlist.list ; sp ; sp = sp->next)
 			mklocal(sp->text);

Added: head/tools/regression/bin/sh/builtins/command10.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/command10.0	Sat Mar  6 17:31:09 2010	(r204802)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if ! eval "[ $* ]"; then
+		echo "Failed: $*"
+		: $((failures += 1))
+	fi
+}
+
+check '"$(f() { shift x; }; { command eval f 2>/dev/null; } >/dev/null; echo hi)" = hi'
+
+exit $((failures > 0))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003061731.o26HVA5F089437>