From owner-freebsd-arch@FreeBSD.ORG Tue Jul 8 12:28:06 2008 Return-Path: Delivered-To: arch@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A16E41065684; Tue, 8 Jul 2008 12:28:06 +0000 (UTC) (envelope-from babkin@verizon.net) Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by mx1.freebsd.org (Postfix) with ESMTP id 805648FC15; Tue, 8 Jul 2008 12:28:06 +0000 (UTC) (envelope-from babkin@verizon.net) Received: from verizon.net ([63.24.211.81]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0K3O00E7UTAJEDW1@vms046.mailsrvcs.net>; Tue, 08 Jul 2008 07:27:57 -0500 (CDT) Date: Tue, 08 Jul 2008 08:32:18 -0400 From: Sergey Babkin Sender: root To: Robert Watson Message-id: <48735E52.65BE464B@verizon.net> MIME-version: 1.0 X-Mailer: Mozilla 4.7 [en] (X11; U; FreeBSD 4.7-RELEASE i386) Content-type: text/plain; charset=koi8-r Content-transfer-encoding: 7bit X-Accept-Language: en, ru References: <9484951.340521215467447990.JavaMail.root@vms126.mailsrvcs.net> <20080708001929.E63144@fledge.watson.org> Cc: arch@FreeBSD.ORG, David Schultz , Poul-Henning Kamp Subject: Re: Proposal: a revoke() system call X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jul 2008 12:28:06 -0000 Robert Watson wrote: > > On Mon, 7 Jul 2008, Sergey Babkin wrote: > > > This leaves a small race window between fd is checked and read() is > > executed. If in the meantime another thread does close() (and sets > > mystructure.fd to -1), and the third thread does open() then the result of > > this open would use the same fd number as our old fd (since now it's likely > > to be the lowest available number), then read() would happen on a completely > > wrong file. And yes, it does happen in real world. The best workaround I've > > come up with is a small pause between setting mystructure.fd = -1 and > > calling close(). > > > > The point of proposal is to do a close() without freeing the file > > descriptor. > > Which can be accomplished by calling dup2(2) to replace the file descriptor > with another file descriptor, perhaps one to /dev/null. It would be worth Yes, dup2() is certainly a better idea than a separate call. I've just assumed that David is following the discussion so far :-) -SB