sh: Allow EV_EXIT through function calls.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sat, 2 Jul 2011 23:38:15 +0000 (13:38 -1000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sun, 21 Aug 2011 19:10:23 +0000 (12:10 -0700)
commit2b23d27fbc13178e19021a1914a077c3274954f2
tree4158ca9cb24a214ebc7b0ad165fabb6eba5f9e5d
parentb6942187683e0524c76f59c4eae6a5eb85e930fa
sh: Allow EV_EXIT through function calls.

make {...} <redir more consistent.

If EV_EXIT causes an exit, use the exception mechanism to unwind
redirections and local variables. This way, if the final command is a
redirected command, an EXIT trap now executes without the redirections.

Because of these changes, EV_EXIT can now be inherited by the body of a
function, so do so. This means that a function no longer prevents a fork
before an exec being skipped, such as in
  f() { head -1 /etc/passwd; }; echo $(f)

Wrapping a single builtin in a function may still cause an otherwise
unnecessary fork with command substitution, however.

An exit command or -e failure still invokes the EXIT trap with the
original redirections and local variables in place.

Note: this depends on SHELLPROC being gone. A SHELLPROC depended on
keeping the redirections and local variables and only cleaning up the
state to restore them.

Obtained-from:   FreeBSD SVN rev 220978
bin/sh/error.h
bin/sh/eval.c
bin/sh/main.c
tools/regression/bin/sh/execution/fork3.0 [new file with mode: 0644]
tools/regression/bin/sh/execution/redir6.0 [new file with mode: 0644]
tools/regression/bin/sh/execution/redir7.0 [new file with mode: 0644]