X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:subject
	:references:in-reply-to:content-type; q=dns; s=default; b=fr+XIm
	JGwDqrU/XGRKKNfkMxUsXHXenKplamCk+F589mIrD96G20msvvXOS5+tpCRxo52R
	qnJCpP/wNbauGINCuij47z6btDL3YB7zHZ3lky4VvlmYLEf0TPO86/FCJCoP7UJ0
	Qm+ng4wq9LVFchK4kB4aic0YYen6xrP2yj3cc=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:subject
	:references:in-reply-to:content-type; s=default; bh=EwTtn/QDkQda
	S3udNkGgC5RfFjA=; b=wOKGRjLgViQO87CelA/+2M9s0rGS4SqZw3bCLLE4/tsW
	RKa4r+cEkpu2o8VoI3rWJQMSauDYKchu1gOF9yekpKuHNgO/0FrU62XO5E9MISCQ
	YHFHNspZl/WD6anqnHOPsN6BmMDa+CkTObcNPmetsusrlXehapJ1ukckq5aTLqg=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mx1.redhat.com
Message-ID: <52D9A589.2050102@redhat.com>
Date: Fri, 17 Jan 2014 14:50:01 -0700
From: Eric Blake <eblake@redhat.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54
References: <831845.98759.bm@smtp116.sbc.mail.ne1.yahoo.com> <52D55D96.8070407@redhat.com> <946338.89157.bm@smtp116.sbc.mail.ne1.yahoo.com> <52D98E1D.8010907@redhat.com>
In-Reply-To: <52D98E1D.8010907@redhat.com>
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8bXaAKfI1ABQintksme6qLf80Gv76RQrl"
X-IsSubscribed: yes

--8bXaAKfI1ABQintksme6qLf80Gv76RQrl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 01/17/2014 01:10 PM, Eric Blake wrote:
>> However..
>>
>> Do I understand that to say that if the first thing my child does is
>>
>> 	fclose(fp);
>>
>> everything should be hunky-dory?
>=20
> No.  You have to fix things _in the parent, before the fork()_ for
> everything to be hunky-dory.  The easiest way to do that is to
> fflush(NULL) before fork()ing.

The exception to needing to fflush() before forking is when the child
will call exec*() or _exit(), as those paths discard any partially-read
buffers without reflecting them back to the underlying fd, and thus
don't interfere with the parent's notion of where to continue reading
from the fd.

And as it is, all this discussion about fflush(NULL) before fork()
depends on the POSIX folks fixing this bug which I just filed:
http://austingroupbugs.net/view.php?id=3D816

without that fix in POSIX, you could argue that fflush(NULL) won't do
anything to input streams, and that you would have to explicitly call
fflush(stream) for every input stream, for cases where you know your
child is going to exit() rather than _exit() or exec*().

--=20
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--8bXaAKfI1ABQintksme6qLf80Gv76RQrl
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJS2aWJAAoJEKeha0olJ0Nq5PQH/3j7jxvQAWDuiC1DQq5fuW5o
eIOUtu+x4v8vndA0/QXVFuwIDkyKsapUbr+BxJVXBREJcwfbInh+W7C+znLidfUI
teyUPBC4k7OWkGm2TSxMN2Zl5Npp9KCtqouYUqjk3qzFcD81G0Q0StlVcsAtCl0u
AXYcA4yJAgvEw/JslUvojnep4g4Tx2rLY3CIKhFYS0aRQCFOQzHpZR20Cg/H4sfa
3dENnJ+tW+bAHktTdf345SFRWjV7UmvG2zSEJF7MORpXKlXfPBvrmXE1T32I7MCS
ao4X9vazw9zYn99yXjwr6C5wMwQ5gwx5u4tCbQWiSOCmQV3qctV9q5WI0gMPV9A=
=Mc25
-----END PGP SIGNATURE-----

--8bXaAKfI1ABQintksme6qLf80Gv76RQrl--
