diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2013-06-19 12:19:04 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2013-06-19 12:19:04 +0000 |
commit | 59bcb42831352320ead1207b58c638290a6b4f6b (patch) | |
tree | 5cfeecadcedee104716201c75330e829a2a8041d /bin/ksh | |
parent | ccfd9d2628df99c29568fdffefa86e4425ddab6d (diff) |
Commands executed via `foo` or $( bar ) should not inherit "set -e"
status. We can't use XERROK for this (since the command might set
-e itself) so just save & restore the value of FERREXIT for the
comsub() call to execute(). OK jca@
Diffstat (limited to 'bin/ksh')
-rw-r--r-- | bin/ksh/eval.c | 12 | ||||
-rw-r--r-- | bin/ksh/tests/regress.t | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index f966df4778b..28f6e79fe19 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.37 2011/10/11 14:32:43 otto Exp $ */ +/* $OpenBSD: eval.c,v 1.38 2013/06/19 12:19:02 millert Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -863,7 +863,7 @@ comsub(Expand *xp, char *cp) errorf("%s: cannot open $() input", name); xp->split = 0; /* no waitlast() */ } else { - int ofd1, pv[2]; + int errexit, ofd1, pv[2]; openpipe(pv); shf = shf_fdopen(pv[0], SHF_RD, (struct shf *) 0); ofd1 = savefd(1); @@ -871,7 +871,15 @@ comsub(Expand *xp, char *cp) ksh_dup2(pv[1], 1, false); close(pv[1]); } + /* + * Clear FERREXIT temporarily while we execute the command. + * We cannot simply pass XERROK since the tree might include + * its own "set -e". + */ + errexit = Flag(FERREXIT); + Flag(FERREXIT) = 0; execute(t, XFORK|XXCOM|XPIPEO, NULL); + Flag(FERREXIT) = errexit; restfd(1, ofd1); startlast(); xp->split = 1; /* waitlast() */ diff --git a/bin/ksh/tests/regress.t b/bin/ksh/tests/regress.t index f220c55f258..264d415e0fe 100644 --- a/bin/ksh/tests/regress.t +++ b/bin/ksh/tests/regress.t @@ -1,4 +1,4 @@ -# $OpenBSD: regress.t,v 1.13 2013/06/16 12:17:20 millert Exp $ +# $OpenBSD: regress.t,v 1.14 2013/06/19 12:19:03 millert Exp $ # # The first 39 of these tests are from the old Bugs script. @@ -603,7 +603,6 @@ expected-stdout: name: regression-39 description: set -e: errors in command substitutions aren't ignored -expected-fail: yes arguments: !-e! stdin: echo `false; echo hi` |