delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/01/15/11:40:33

X-Recipient: archive-cygwin AT delorie DOT 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 AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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 AT coverity DOT 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 AT cygwin DOT com>
Subject: Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54
References: <831845 DOT 98759 DOT bm AT smtp116 DOT sbc DOT mail DOT ne1 DOT yahoo DOT com>
In-Reply-To: <831845.98759.bm@smtp116.sbc.mail.ne1.yahoo.com>
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 AT bellsouth DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019