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:content-transfer-encoding;
	 q=dns; s=default; b=BJ1jHVwi2hMbyKWF47+2SD7BgTjd4llgXsZ3tZkXrg5
	ZbaSI0UjwOC4R+ee/+gB1XYPWoQZSSd7GUl/1wCGx474MXTbAez/qPPp8CsWBrJp
	w+DoFjup9cDggIZXYPzYjLhZ1erR+4W45dHnrszFLE++De5UAXJtJNppilKuzRTs
	=
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:content-transfer-encoding;
	 s=default; bh=G/K0AbWOpH0tqBuWE4OwiwiDm9k=; b=QVeMKwgEaRj21u+if
	S4jEhbXKS8/awC9D4CnlAGWQyLsWVchFqOCwEQYqDctRKCbs+olMzhWAEb+2ARHH
	Lm+rlqvnNegNKludTCJ1BwJTNTisU8VtOSu9s1MzPoupSo/92X9VunY4zD0xD4vA
	7MlzgmUC2WmAU7LKi/oAeQRf7Q=
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.4 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2
X-HELO: na01-bn1-obe.outbound.protection.outlook.com
Message-ID: <52D6B9DC.50903@coverity.com>
Date: Wed, 15 Jan 2014 11:39:56 -0500
From: Tom Honermann <thonermann@coverity.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>
In-Reply-To: <831845.98759.bm@smtp116.sbc.mail.ne1.yahoo.com>
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: BLUPR07CA037.namprd07.prod.outlook.com (10.141.200.42) To BY2PR05MB598.namprd05.prod.outlook.com (10.141.219.19)
X-Forefront-PRVS: 00922518D8
X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009001)(689001)(679001)(779001)(24454002)(199002)(189002)(479174003)(377454003)(5423002)(51704005)(51856001)(53806001)(47446002)(36756003)(50466002)(74876001)(42186004)(83322001)(77982001)(74706001)(59766001)(92726001)(92566001)(63696002)(54356001)(19580395003)(90146001)(74502001)(64126003)(76482001)(77096001)(19580405001)(74662001)(4396001)(46102001)(49866001)(56776001)(85306002)(47976001)(50986001)(47736001)(76796001)(87976001)(76786001)(54316002)(85852003)(87266001)(65956001)(81816001)(65806001)(79102001)(83506001)(80976001)(69226001)(31966008)(23756003)(74366001)(33656001)(56816005)(93136001)(66066001)(81686001)(81542001)(47776003)(80022001)(81342001)(83072002)(93516002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR05MB598;H:[192.168.1.12];CLIP:96.253.80.174;FPR:;RD:InfoNoRecords;A:1;MX:1;LANG:en;
X-OriginatorOrg: coverity.com
X-IsSubscribed: yes

On 01/13/2014 11:06 AM, tednolan@bellsouth.net wrote:
...
> 		switch (fork()) {
> 			
> 			/* error */
> 			case -1:
...
> 			/* child */
> 			case 0:
> 				fprintf(stderr, "child\n"); fflush(stderr);
> 				exit(0);
> 				break;

The above code is incorrect.  It is always wrong to call exit() from a 
forked process that has not yet called one of the exec() family of 
functions.  _exit() should be called instead.  Best case, calling exit() 
will result in double flushing of any stream buffers held by the parent 
at the time fork() is called (since the buffers will (eventually) be 
flushed by the parent as well as the child (unless at least one of the 
processes aborts or exits with _exit()).

Tom.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

