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))
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to