From rse@engelschall.com  Wed Aug  7 07:23:06 2002
Return-Path: <rse@engelschall.com>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B8E5A37B400
	for <freebsd-gnats-submit@freebsd.org>; Wed,  7 Aug 2002 07:23:06 -0700 (PDT)
Received: from visp.engelschall.com (en4.engelschall.com [195.27.176.146])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DD47043E88
	for <freebsd-gnats-submit@freebsd.org>; Wed,  7 Aug 2002 07:23:05 -0700 (PDT)
	(envelope-from rse@engelschall.com)
Received: by visp.engelschall.com (Postfix, from userid 1005)
	id 25AE94CE6E2; Wed,  7 Aug 2002 16:23:04 +0200 (CEST)
Received: by en1.engelschall.com (Postfix, from userid 10000)
	id 6F12B28693; Wed,  7 Aug 2002 16:22:52 +0200 (CEST)
Message-Id: <20020807142252.6F12B28693@en1.engelschall.com>
Date: Wed,  7 Aug 2002 16:22:52 +0200 (CEST)
From: Ralf S.Engelschall <rse@engelschall.com>
Reply-To: Ralf S.Engelschall <rse@engelschall.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: dev@de.cw.net
Subject: /bin/sh bug on expanding $? in here-documents
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         41410
>Category:       bin
>Synopsis:       sh(1) bug on expanding $? in here-documents
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 07 07:30:02 PDT 2002
>Closed-Date:    Sat Aug 13 21:44:14 UTC 2011
>Last-Modified:  Sat Aug 13 21:44:14 UTC 2011
>Originator:     Ralf S. Engelschall
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
Cavle & Wireless Germany
>Environment:
System: FreeBSD en1.engelschall.com 4.6-STABLE FreeBSD 4.6-STABLE #0: Fri Jul 26 19:25:01 CEST 2002 root@en1.engelschall.com:/v/dsk/0/g/src/sys/compile/EN1 i386

>Description:

While debugging a build problem of GNU Tar 1.3.25 on FreeBSD 4.6-STABLE
for OpenPKG, I discovered a bug in /bin/sh which is triggered by a
construct in Tar's generated GNU Autoconf script "configure". The bug is
that in here-documents the shell-variable $? is expanded incorrectly.
The appended sample script buggy.sh demonstrates the problem. I ran
"uname -a; /bin/sh buggy.sh | grep attempt" on some of our development
machines and it resulted in the following output:

FreeBSD dv1 4.6-STABLE FreeBSD 4.6-STABLE #0: Sun Jul 14 20:58:49 CEST 2002
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=0 $1=foo $2=bar $baz=quux
attempt 3: $?=0 $1=foo $2=bar $baz=quux
FreeBSD dv2 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Sun Jul 28 10:54:41 CEST 2002
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=0 $1=foo $2=bar $baz=quux
attempt 3: $?=0 $1=foo $2=bar $baz=quux
NetBSD dv3 1.6_BETA3 NetBSD 1.6_BETA3 (DV3) #0: Thu Jun 27 19:09:59 UTC 2002
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=0 $1=foo $2=bar $baz=quux
attempt 3: $?=0 $1=foo $2=bar $baz=quux
Linux dv4 2.4.9-21 #1 Thu Jan 17 14:16:30 EST 2002 i686 unknown
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux
Linux dv5 2.2.20 #1 Sat Nov 3 18:25:00 CET 2001 i686 unknown
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux
Linux dv6 2.4.19 #1 SMP Sat Aug 3 15:48:01 CEST 2002 i686 unknown
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux
SunOS dv8 5.8 Generic_108528-15 sun4u sparc SUNW,Ultra-250
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux
SunOS dv9 5.9 Generic sun4u sparc SUNW,Ultra-250
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux
OpenUNIX dv11 5 8.0.0 i386 x86at Caldera UNIX_SVR5
attempt 1: $?=1 $1=foo $2=bar $baz=quux
attempt 2: $?=1 $1=foo $2=bar $baz=quux
attempt 3: $?=1 $1=foo $2=bar $baz=quux

As one can see, the bug is not really FreeBSD specific, because it also
occurs on NetBSD. But all other Unix flavors I tested consistently show
the expected result (three times the value 1). The same happens with GNU
Bash on all platforms (every time the correct value 1). So I have to
assume that the output of /bin/sh on FreeBSD and NetBSD is incorrect and
caused by a bug.

=====================================================================
#!/bin/sh -x
#  buggy.sh

set -- foo bar
baz=quux

#   attempt #1 (simple echo for comparison)
test yes != yes
echo "attempt 1: \$?=$? \$1=$1 \$2=$2 \$baz=$baz"

#   attempt #2 (small here-document)
test yes != yes
cat <<EOF
attempt 2: \$?=$? \$1=$1 \$2=$2 \$baz=$baz
EOF

#   attempt #3 (large here-document >= 4KB)
test yes != yes
cat <<EOF
attempt 3: \$?=$? \$1=$1 \$2=$2 \$baz=$baz
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789
EOF
=====================================================================

>How-To-Repeat:

$ /bin/sh
$ (exit 42)
$ echo "$?" 
42
$ (exit 42)   
$ cat <<EOF
> $?
> EOF
0
$ _

>Fix:

I already poked around in the source of /bin/sh in HEAD and RELENG_4, but
was not able to really discover or even solve the bug. I only discovered
that the source of the failure in "attempt 2" seems to be caused by
an assignment of the exit value in eval.c:

Index: eval.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/eval.c,v
retrieving revision 1.27.2.4
diff -u -d -r1.27.2.4 eval.c
--- eval.c      19 Jul 2002 04:38:51 -0000      1.27.2.4
+++ eval.c      7 Aug 2002 14:09:07 -0000
@@ -442,7 +442,9 @@
        for (redir = n ; redir ; redir = redir->nfile.next) {
                struct arglist fn;
                fn.lastp = &fn.list;
+#if 0
                oexitstatus = exitstatus;
+#endif
                switch (redir->type) {
                case NFROM:
                case NTO:

With this test-removal I get at least "attempt 2: $?=1 $1=foo $2=bar
$baz=quux". But perhaps now something else is broken, of course. So we
really need someone with more knowledge of the /bin/sh internals to dive
into the source and fix it for us.

>Release-Note:
>Audit-Trail:

From: "Artem 'Zazoobr' Ignatjev" <timon@memphis.mephi.ru>
To: freebsd-gnats-submit@FreeBSD.org, rse@engelschall.com
Cc:  
Subject: Re: bin/41410: /bin/sh bug on expanding $? in here-documents
Date: Mon, 12 Aug 2002 19:52:55 +0400

 I've hacked around a bit, and found following code :
 eval.c:649:     oexitstatus = exitstatus;
 eval.c:650:     exitstatus = 0;          
 
 then, in function expredir:
 eval.c:454:    for (redir = n ; redir ; redir = redir->nfile.next) { 
 eval.c:455:            struct arglist fn;                            
 eval.c:456:            fn.lastp = &fn.list;                          
 eval.c:457:            oexitstatus = exitstatus;                     
 
 But once we're here, exitstatus is already 0
 I've tried to remove offending line #650, and your script showed the
 same values three times.
 I've also modified it to check, whether it's required to explicitly set
 exitstatus to 0, testing "yes" for being "yes" each time after your
 attempt. Output is as shown:
 
 attempt 1: $?=1 $1=foo $2=bar $baz=quux 
 attempt 1': $?=0 $1=foo $2=bar $baz=quux
 attempt 2: $?=1 $1=foo $2=bar $baz=quux 
 attempt 2': $?=0 $1=foo $2=bar $baz=quux
 attempt 3: $?=1 $1=foo $2=bar $baz=quux 
 attempt 3': $?=0 $1=foo $2=bar $baz=quux
 
 Here's my version of your script:
 begin 644 buggy.sh.gz                                        
 M'XL(`!#65ST``^W8OT[#,!`&\-U/<6TB4880DI:_:JB$!`M#7X#%"2:I%,?!
 M=B2*>'B<0EL52AL&!M!71;T,]SM_E]%>+RR4%*&=256%1F>A*=Q#S"-*FSR?
 M'YF",2,L!0$]*D4IURSE+\E3TSRSMHNXM4+6EKR(!F8FZU*0R`KENC5E2M9<
 MSXRJ#ID5QM)<&.HE;6&+IOY21Y=T[T\2?^)*E/B1*W'BQZZTI[5__?6$K0,.
 M.DS8#!R[P)*7)15"B^!!98T4E?V:-..6QN.;Z2U;TGCO6:QM_Y28OO^MS]C1
 M]-&Z"K%_X_<4&TL/:5!RG8O-I>DJH='=]8[=Z95R+>KEH%6*X?X0QU$\')V<
 MGIU?_/P-&!@8&!@8&!@8&!@8&!CX_^(MUR<=[B(ZW(C\T>\!#`P,#`P,#`P,
 4#`P,#`S\RWAQ&?$&0[*9Y"LC````                                
 `                                                            
 end                                                          
 And here's the suggested patch:
 
 --- /usr/src/bin/sh/eval.c	Thu Jul  5 04:41:14 2001
 +++ /usr/src/bin/sh/eval.c	Mon Aug 12 19:29:00 2002
 @@ -647,7 +647,7 @@
 	varflag = 1;
 	oexitstatus = exitstatus;
 -	exitstatus = 0;
 +//	exitstatus = 0;
 	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
 		char *p = argp->narg.text;
 		if (varflag && is_name(*p)) {
 --- Patch ends here ---
 			Sinceherely yours, Artem 'Zazoobr' Ignatjev.

From: "Ralf S. Engelschall" <rse@engelschall.com>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: bin/41410: /bin/sh bug on expanding $? in here-documents
Date: Wed, 4 Dec 2002 13:09:15 +0100

 The companion PR in NetBSD was fixed a few days ago now with the
 following commit:
 
 http://cvsweb.netbsd.org/bsdweb.cgi/basesrc/bin/sh/eval.c.diff?r1=1.67&r2=1.68
 
 | Fixes from David Laight:
 | - ansification
 | - format of output of jobs command (etc)
 | - job identiers %+, %- etc
 | - $? and $(...)
 | - correct quoting of output of set, export -p and readonly -p
 | - differentiation between nornal and 'posix special' builtins
 | - correct behaviour (posix) for errors on builtins and special builtins
 | - builtin printf and kill
 | - set -o debug (if compiled with DEBUG)
 | - cd src obj (as ksh - too useful to do without)
 | - unset -e name, remove non-readonly variable from export list.
 |   (so I could unset -e PS1 before running the test shell...)
 
 Unfortunately this fix contains also other changes, so someone first has
 to extract out the parts which apply only to this problem here. Or do we
 want all those fixes?
                                        Ralf S. Engelschall
                                        rse@engelschall.com
                                        www.engelschall.com
Responsible-Changed-From-To: freebsd-bugs->tjr 
Responsible-Changed-By: ceri 
Responsible-Changed-When: Sat Dec 27 08:59:43 PST 2003 
Responsible-Changed-Why:  
tjr seems to be our sh(1) guru. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 
Responsible-Changed-From-To: tjr->freebsd-bugs 
Responsible-Changed-By: tjr 
Responsible-Changed-When: Sat Feb 14 23:36:04 PST 2004 
Responsible-Changed-Why:  
Unassign due to lack of time and interest. Perhaps someone else 
will pick this up. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: stefanf 
Responsible-Changed-When: Thu Jun 15 07:41:06 UTC 2006 
Responsible-Changed-Why:  
I'll try to fix this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 
Responsible-Changed-From-To: stefanf->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Jun 5 12:35:13 UTC 2011 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/41410: commit references a PR
Date: Sun,  5 Jun 2011 12:46:40 +0000 (UTC)

 Author: jilles
 Date: Sun Jun  5 12:46:26 2011
 New Revision: 222715
 URL: http://svn.freebsd.org/changeset/base/222715
 
 Log:
   sh: Add already working testcases for $? in here-document.
   
   If the here-document is attached to a compound command or subshell, $?
   already works properly. This is both a workaround for bin/41410 and a
   requirement for a true fix for bin/41410.
   
   PR:		bin/41410
   MFC after:	1 week
 
 Added:
   head/tools/regression/bin/sh/expansion/heredoc1.0   (contents, props changed)
 
 Added: head/tools/regression/bin/sh/expansion/heredoc1.0
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/tools/regression/bin/sh/expansion/heredoc1.0	Sun Jun  5 12:46:26 2011	(r222715)
 @@ -0,0 +1,25 @@
 +# $FreeBSD$
 +
 +f() { return $1; }
 +
 +[ `f 42; { cat; } <<EOF
 +$?
 +EOF
 +` = 42 ] || echo compound command bad
 +
 +[ `f 42; (cat) <<EOF
 +$?
 +EOF
 +` = 42 ] || echo subshell bad
 +
 +long=`printf %08192d 0`
 +
 +[ `f 42; { cat; } <<EOF
 +$long.$?
 +EOF
 +` = $long.42 ] || echo long compound command bad
 +
 +[ `f 42; (cat) <<EOF
 +$long.$?
 +EOF
 +` = $long.42 ] || echo long subshell bad
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/41410: commit references a PR
Date: Sun,  5 Jun 2011 14:13:29 +0000 (UTC)

 Author: jilles
 Date: Sun Jun  5 14:13:15 2011
 New Revision: 222716
 URL: http://svn.freebsd.org/changeset/base/222716
 
 Log:
   sh: Fix $? in heredocs on simple commands.
   
   PR:		bin/41410
 
 Added:
   head/tools/regression/bin/sh/expansion/heredoc2.0   (contents, props changed)
 Modified:
   head/bin/sh/eval.c
 
 Modified: head/bin/sh/eval.c
 ==============================================================================
 --- head/bin/sh/eval.c	Sun Jun  5 12:46:26 2011	(r222715)
 +++ head/bin/sh/eval.c	Sun Jun  5 14:13:15 2011	(r222716)
 @@ -409,6 +409,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) {
 @@ -436,6 +437,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)) {
 @@ -478,7 +480,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:
 
 Added: head/tools/regression/bin/sh/expansion/heredoc2.0
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/tools/regression/bin/sh/expansion/heredoc2.0	Sun Jun  5 14:13:15 2011	(r222716)
 @@ -0,0 +1,15 @@
 +# $FreeBSD$
 +
 +f() { return $1; }
 +
 +[ `f 42; cat <<EOF
 +$?
 +EOF
 +` = 42 ] || echo simple command bad
 +
 +long=`printf %08192d 0`
 +
 +[ `f 42; cat <<EOF
 +$long.$?
 +EOF
 +` = $long.42 ] || echo long simple command bad
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun Jun 5 14:44:46 UTC 2011 
State-Changed-Why:  
Fixed in 9-current. An MFC to 8-stable may be possible. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/41410: commit references a PR
Date: Sat, 13 Aug 2011 21:34:05 +0000 (UTC)

 Author: jilles
 Date: Sat Aug 13 21:33:50 2011
 New Revision: 224854
 URL: http://svn.freebsd.org/changeset/base/224854
 
 Log:
   MFC r222716: sh: Fix $? in heredocs on simple commands.
   
   The patch is slightly different because redirected compound commands are
   handled differently in stable/8 (no separate function, redirection errors
   are fatal).
   
   PR:		bin/41410
 
 Added:
   stable/8/tools/regression/bin/sh/expansion/heredoc2.0
      - copied unchanged from r222716, head/tools/regression/bin/sh/expansion/heredoc2.0
 Modified:
   stable/8/bin/sh/eval.c
 Directory Properties:
   stable/8/bin/sh/   (props changed)
   stable/8/tools/regression/bin/sh/   (props changed)
 
 Modified: stable/8/bin/sh/eval.c
 ==============================================================================
 --- stable/8/bin/sh/eval.c	Sat Aug 13 17:29:37 2011	(r224853)
 +++ stable/8/bin/sh/eval.c	Sat Aug 13 21:33:50 2011	(r224854)
 @@ -221,6 +221,7 @@ evaltree(union node *n, int flags)
  		evaltree(n->nbinary.ch2, flags);
  		break;
  	case NREDIR:
 +		oexitstatus = exitstatus;
  		expredir(n->nredir.redirect);
  		redirect(n->nredir.redirect, REDIR_PUSH);
  		evaltree(n->nredir.n, flags);
 @@ -400,6 +401,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) {
 @@ -428,7 +430,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:
 
 Copied: stable/8/tools/regression/bin/sh/expansion/heredoc2.0 (from r222716, head/tools/regression/bin/sh/expansion/heredoc2.0)
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ stable/8/tools/regression/bin/sh/expansion/heredoc2.0	Sat Aug 13 21:33:50 2011	(r224854, copy of r222716, head/tools/regression/bin/sh/expansion/heredoc2.0)
 @@ -0,0 +1,15 @@
 +# $FreeBSD$
 +
 +f() { return $1; }
 +
 +[ `f 42; cat <<EOF
 +$?
 +EOF
 +` = 42 ] || echo simple command bad
 +
 +long=`printf %08192d 0`
 +
 +[ `f 42; cat <<EOF
 +$long.$?
 +EOF
 +` = $long.42 ] || echo long simple command bad
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jilles 
State-Changed-When: Sat Aug 13 21:43:17 UTC 2011 
State-Changed-Why:  
Fixed (at last) in 9-current and 8-stable, no MFC to 7-stable planned. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=41410 
>Unformatted:
