summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/sh/eval.c9
-rw-r--r--tools/regression/bin/sh/builtins/trap4.017
2 files changed, 22 insertions, 4 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 14dd15f..0bb5322 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -671,6 +671,7 @@ safe_builtin(int idx, int argc, char **argv)
/*
* Execute a simple command.
+ * Note: This may or may not return if (flags & EV_EXIT).
*/
static void
@@ -707,6 +708,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
arglist.lastp = &arglist.list;
varlist.lastp = &varlist.list;
varflag = 1;
+ jp = NULL;
do_clearcmdentry = 0;
oexitstatus = exitstatus;
exitstatus = 0;
@@ -965,7 +967,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
evalskip = 0;
skipcount = 0;
}
- if (flags & EV_EXIT)
+ if (jp)
exitshell(exitstatus);
} else if (cmdentry.cmdtype == CMDBUILTIN) {
#ifdef DEBUG
@@ -1013,13 +1015,12 @@ cmddone:
out1 = &output;
out2 = &errout;
freestdout();
+ handler = savehandler;
if (e != EXSHELLPROC) {
commandname = savecmdname;
- if (flags & EV_EXIT) {
+ if (jp)
exitshell(exitstatus);
- }
}
- handler = savehandler;
if (flags == EV_BACKCMD) {
backcmd->buf = memout.buf;
backcmd->nleft = memout.nextc - memout.buf;
diff --git a/tools/regression/bin/sh/builtins/trap4.0 b/tools/regression/bin/sh/builtins/trap4.0
new file mode 100644
index 0000000..7f2080e
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/trap4.0
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+
+v=$(
+ exec 3>&1
+ : <fifo1 &
+ {
+ wait $!
+ trap 'trap "" PIPE; echo trapped >&3 2>/dev/null' PIPE
+ echo x 2>/dev/null
+ } >fifo1
+)
+test "$v" = trapped
OpenPOWER on IntegriCloud