summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-04-23 22:28:56 +0000
committerjilles <jilles@FreeBSD.org>2011-04-23 22:28:56 +0000
commitf250dc2f449b2e81b05be3a09647011b8a783e81 (patch)
tree1769bded7ead74e70ac17d9570ffab4c573e0ade /tools
parentd98bdded177a447c277598fa1add5fef3738ed9f (diff)
downloadFreeBSD-src-f250dc2f449b2e81b05be3a09647011b8a783e81.zip
FreeBSD-src-f250dc2f449b2e81b05be3a09647011b8a783e81.tar.gz
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bin/sh/execution/fork3.04
-rw-r--r--tools/regression/bin/sh/execution/redir6.021
-rw-r--r--tools/regression/bin/sh/execution/redir7.021
3 files changed, 46 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/execution/fork3.0 b/tools/regression/bin/sh/execution/fork3.0
new file mode 100644
index 0000000..3cb678c
--- /dev/null
+++ b/tools/regression/bin/sh/execution/fork3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+result=$(${SH} -c 'f() { ps -p $$ -o comm=; }; f')
+test "$result" = "ps"
diff --git a/tools/regression/bin/sh/execution/redir6.0 b/tools/regression/bin/sh/execution/redir6.0
new file mode 100644
index 0000000..4e3ac0c
--- /dev/null
+++ b/tools/regression/bin/sh/execution/redir6.0
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ if [ "$2" != "$3" ]; then
+ echo "Failure at $1" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+check $LINENO "$(trap "echo bye" EXIT; : >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; { :; } >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (:) >/dev/null)" bye
+check $LINENO "$(trap "echo bye" EXIT; (: >/dev/null))" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; : >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; { :; } >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (:) >/dev/null')" bye
+check $LINENO "$(${SH} -c 'trap "echo bye" EXIT; (: >/dev/null)')" bye
+
+exit $((failures > 0))
diff --git a/tools/regression/bin/sh/execution/redir7.0 b/tools/regression/bin/sh/execution/redir7.0
new file mode 100644
index 0000000..2487bcf
--- /dev/null
+++ b/tools/regression/bin/sh/execution/redir7.0
@@ -0,0 +1,21 @@
+# $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))
OpenPOWER on IntegriCloud