mirror of
https://github.com/opnsense/src.git
synced 2026-02-14 16:23:25 -05:00
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.
21 lines
771 B
Text
21 lines
771 B
Text
# $FreeBSD$
|
|
|
|
failures=0
|
|
|
|
check() {
|
|
if [ "$2" != "$3" ]; then
|
|
echo "Failure at $1" >&2
|
|
failures=$((failures + 1))
|
|
fi
|
|
}
|
|
|
|
check $LINENO "$(trap "echo bye" EXIT; f() { :; }; f >/dev/null)" bye
|
|
check $LINENO "$(trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null)" bye
|
|
check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f) >/dev/null)" bye
|
|
check $LINENO "$(trap "echo bye" EXIT; f() { :; }; (f >/dev/null))" bye
|
|
check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; f >/dev/null')" bye
|
|
check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; { f; } >/dev/null')" bye
|
|
check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f) >/dev/null')" bye
|
|
check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; f() { :; }; (f >/dev/null)')" bye
|
|
|
|
exit $((failures > 0))
|