From: Peter Avalos Date: Sun, 21 Aug 2011 20:10:39 +0000 (-0700) Subject: sh: Fix $? in heredocs on simple commands. X-Git-Tag: v2.12.0~154 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/87838cc9ea8a6c1c9a2cc20b78bfbc97026c3c04?hp=84021a35cdfe43b836c506f2d8f23d527b78b957 sh: Fix $? in heredocs on simple commands. Obtained-from: FreeBSD 222716 --- diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 1de8c311d0..567a040d00 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)eval.c 8.9 (Berkeley) 6/8/95 - * $FreeBSD: src/bin/sh/eval.c,v 1.106 2011/06/04 11:28:42 jilles Exp $ + * $FreeBSD: src/bin/sh/eval.c,v 1.107 2011/06/05 14:13:15 jilles Exp $ */ #include @@ -410,6 +410,7 @@ evalsubshell(union node *n, int flags) struct job *jp; int backgnd = (n->type == NBACKGND); + oexitstatus = exitstatus; expredir(n->nredir.redirect); if ((!backgnd && flags & EV_EXIT && !have_traps()) || forkshell(jp = makejob(n, 1), n, backgnd) == 0) { @@ -437,6 +438,7 @@ evalredir(union node *n, int flags) struct jmploc *savehandler; volatile int in_redirect = 1; + oexitstatus = exitstatus; expredir(n->nredir.redirect); savehandler = handler; if (setjmp(jmploc.loc)) { @@ -479,7 +481,6 @@ expredir(union node *n) for (redir = n ; redir ; redir = redir->nfile.next) { struct arglist fn; fn.lastp = &fn.list; - oexitstatus = exitstatus; switch (redir->type) { case NFROM: case NTO: diff --git a/tools/regression/bin/sh/expansion/heredoc2.0 b/tools/regression/bin/sh/expansion/heredoc2.0 new file mode 100644 index 0000000000..2d86d5ea40 --- /dev/null +++ b/tools/regression/bin/sh/expansion/heredoc2.0 @@ -0,0 +1,15 @@ +# $FreeBSD: src/tools/regression/bin/sh/expansion/heredoc2.0,v 1.1 2011/06/05 14:13:15 jilles Exp $ + +f() { return $1; } + +[ `f 42; cat <