From 45496405c65570e322e098be643b98d69cee39e2 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 23 Apr 2011 22:28:56 +0000 Subject: [PATCH] sh: Allow EV_EXIT through function calls, make {...} next) mklocal(sp->text); exitstatus = oexitstatus; - if (flags & EV_TESTED) - evaltree(getfuncnode(cmdentry.u.func), EV_TESTED); - else - evaltree(getfuncnode(cmdentry.u.func), 0); + evaltree(getfuncnode(cmdentry.u.func), + flags & (EV_TESTED | EV_EXIT)); INTOFF; unreffunc(cmdentry.u.func); poplocalvars(); @@ -982,7 +981,10 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) savehandler = handler; if (setjmp(jmploc.loc)) { e = exception; - exitstatus = (e == EXINT)? SIGINT+128 : 2; + if (e == EXINT) + exitstatus = SIGINT+128; + else if (e != EXEXIT) + exitstatus = 2; goto cmddone; } handler = &jmploc; @@ -1018,8 +1020,7 @@ cmddone: backcmd->nleft = memout.nextc - memout.buf; memout.buf = NULL; } - if (cmdentry.u.index != EXECCMD && - (e == -1 || e == EXERROR || e == EXEXEC)) + if (cmdentry.u.index != EXECCMD) popredir(); if (e != -1) { if ((e != EXERROR && e != EXEXEC) diff --git a/bin/sh/main.c b/bin/sh/main.c index c5de8990a2e1..12a7ff2d1733 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -111,7 +111,8 @@ main(int argc, char *argv[]) break; } - if (state == 0 || iflag == 0 || ! rootshell) + if (state == 0 || iflag == 0 || ! rootshell || + exception == EXEXIT) exitshell(exitstatus); reset(); if (exception == EXINT) diff --git a/tools/regression/bin/sh/execution/fork3.0 b/tools/regression/bin/sh/execution/fork3.0 new file mode 100644 index 000000000000..3cb678c2d08a --- /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 000000000000..4e3ac0cae055 --- /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 000000000000..2487bcf2fc0d --- /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))