From owner-svn-src-all@FreeBSD.ORG Tue Mar 16 17:55:07 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49276106564A; Tue, 16 Mar 2010 17:55:07 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail06.syd.optusnet.com.au (mail06.syd.optusnet.com.au [211.29.132.187]) by mx1.freebsd.org (Postfix) with ESMTP id D74528FC19; Tue, 16 Mar 2010 17:55:06 +0000 (UTC) Received: from c122-106-169-91.carlnfd1.nsw.optusnet.com.au (c122-106-169-91.carlnfd1.nsw.optusnet.com.au [122.106.169.91]) by mail06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o2GHt0dM023702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 17 Mar 2010 04:55:03 +1100 Date: Wed, 17 Mar 2010 04:55:01 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Poul-Henning Kamp In-Reply-To: <44640.1268676905@critter.freebsd.dk> Message-ID: <20100317041500.V26092@delplex.bde.org> References: <44640.1268676905@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Bruce Evans Subject: Re: svn commit: r205165 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Mar 2010 17:55:07 -0000 On Mon, 15 Mar 2010, Poul-Henning Kamp wrote: > In message <20100316024446.A24853@delplex.bde.org>, Bruce Evans writes: >> On Tue, 16 Mar 2010, Bruce Evans wrote: > >> Due to the way that daemon() works, it is really an error to have any >> open streams when it is called. This is also undocumented, except >> implicitly. The errors are: >> - unflushed output on stdout and stderr won't get flushed normally by ^^^^^^^^ >> the child. stdout and stderr are redirected so it will go there if >> the child erroneously (?) uses these streams or simply calls exit() >> which will give the default flush. > > The in-core FILE buffers are copied in the child process, so they > should most certainly not be flushed, but rather, as they correctly > are, discarded, so that when the child causes the flush, the content > is only output once. Nope. Even if the child causes the flush, the content of stdout and stderr is not flushed normally since it is redirected to /dev/null. Unflushed input in stdin is handled more brokenly: although stdin is redirected to /dev/null, input on it can still be read via stdin's buffer. Inheriting unflushed input on other streams is a feature (unless these streams are open on fd's 0-2; then these streams will have the same corruption as std* streams open on their normal fd's 0-2). As described in the unquoted part of my reply above, all streams should be flushed by the parent before the fork(), so that they are flushed normally. daemon(3) has a lot to say about problems with open fd's 0-2, but it says nothing about the extra problems with open streams on these descriptors. It documents as a feature that fd's above 2 are inherited normally. It also says too little about the implementation always using fork() (it cross-references fork() but doesn't say that the context is always a child context on successful completion). Bruce