From owner-freebsd-threads@FreeBSD.ORG Thu Dec 29 05:50:08 2005 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9E02016A41F for ; Thu, 29 Dec 2005 05:50:08 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A8FA043D55 for ; Thu, 29 Dec 2005 05:50:07 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id jBT5o7Ul072508 for ; Thu, 29 Dec 2005 05:50:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id jBT5o7Cn072507; Thu, 29 Dec 2005 05:50:07 GMT (envelope-from gnats) Date: Thu, 29 Dec 2005 05:50:07 GMT Message-Id: <200512290550.jBT5o7Cn072507@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: Dmitrij Tejblum Cc: Subject: Re: threads/79887: [patch] freopen() isn't thread-safe X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dmitrij Tejblum List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Dec 2005 05:50:08 -0000 The following reply was made to PR threads/79887; it has been noted by GNATS. From: Dmitrij Tejblum To: David Xu Cc: bug-followup@freebsd.org Subject: Re: threads/79887: [patch] freopen() isn't thread-safe Date: Thu, 29 Dec 2005 08:43:15 +0300 David Xu wrote: > Dmitrij Tejblum wrote: > >> >> David Xu wrote: >> >>> Indeed, this a bug, but the patch you provided breaks the samentic the >>> FILE structure was designed for, here you conditionally call >>> fp->_close(), this is incorrect, because the hook may be an external >>> function, it should always be called to notify external code. >> >> >> >> I only assume that >> 1) _file and _close fields are internal to stdio, i.e. only stdio >> code manipulate with them directly >> 2) If _file != -1, then the FILE is associated with the file >> descriptor, fp->_close == __sclose (because the only code that can >> set fp_close to something different is funopen, and it set _file to >> -1) and __sclose just close the _fp->_file >> If so, we know that dup2() will close the descriptor too, dup2() is >> required to do it. >> > I think we allow _close and others to be changed by user code unless > someone can clarify that this is not allowed now, otherwise your > assumption is false. Well, this is C, not C++, so there cannot be strict difference between allowed and disallowed. But the _close field is not required by any standarts (funopen() too) and is not documented by manpages (I checked manpages with grep). And there does exist documented interface for setting _close: funopen(). Thus _close is internal.