From owner-freebsd-threads@FreeBSD.ORG Thu Dec 29 04:20:07 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 3578416A420 for ; Thu, 29 Dec 2005 04:20:07 +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 7660D43D69 for ; Thu, 29 Dec 2005 04:20:06 +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 jBT4K69E068278 for ; Thu, 29 Dec 2005 04:20:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id jBT4K6Bo068277; Thu, 29 Dec 2005 04:20:06 GMT (envelope-from gnats) Date: Thu, 29 Dec 2005 04:20:06 GMT Message-Id: <200512290420.jBT4K6Bo068277@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: David Xu 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: David Xu List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Dec 2005 04:20:07 -0000 The following reply was made to PR threads/79887; it has been noted by GNATS. From: David Xu To: bug-followup@freebsd.org, tejblum@yandex-team.ru Cc: Subject: Re: threads/79887: [patch] freopen() isn't thread-safe Date: Thu, 29 Dec 2005 12:16:01 +0800 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 think the right fix is to fix those code which is still using STDERR_FILENO, or don't do following hack in freopen.c: if (wantfd >= 0 && f != wantfd) { if (_dup2(f, wantfd) >= 0) { (void)_close(f); f = wantfd; } } This is not required by standard. David Xu