From owner-freebsd-hackers Wed Apr 21 6: 9:54 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from titan.metropolitan.at (mail.metropolitan.at [195.212.98.131]) by hub.freebsd.org (Postfix) with ESMTP id 91D2D151B4 for ; Wed, 21 Apr 1999 06:09:47 -0700 (PDT) (envelope-from mladavac@metropolitan.at) Received: by TITAN with Internet Mail Service (5.0.1458.49) id <26KYDBAF>; Wed, 21 Apr 1999 15:09:54 +0200 Message-ID: <55586E7391ACD211B9730000C11002761795EE@r-lmh-wi-100.corpnet.at> From: Ladavac Marino To: 'Graham Wheeler' , hackers@freebsd.org Subject: RE: File locking problem Date: Wed, 21 Apr 1999 15:05:41 +0200 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1458.49) Content-Type: text/plain Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > -----Original Message----- > From: Graham Wheeler [SMTP:gram@cdsec.com] > Sent: Wednesday, April 21, 1999 2:57 PM > To: hackers@freebsd.org > Subject: Re: File locking problem > > I have now found the problem - it is a race between the process which > is reading the directory contents and the one which is unlinking the > file. The one that reads the directory gets the name of a file that > the > other is busy processing. The one doing the processing does the unlink > and close, at which point the one reading the directory does an open. > The problem is that it does the open with both read and write > permission, and as a consequence ends up creating a new empty file > with > the old name. > > I'm not quite sure how I'm going to solve this one yet, but at least > there is now a rational explanation. [ML] Sounds like a race in your code, if I have understood you correctly. Obviously, you will need to synchronize these two processes somehow. Either the reader should not read the directory while the unlinker is doing its deed (flock on a directory--sholud work, you can open a directory as a file, you should be able to lock it as well, but I cannot test that now since this NT box in front of me just doesn't cut it), or, a hacky solution, the reader opens the file readonly first, and if this succeeds, read-write (it then closes the readonly fd). /Marino > -- > Dr Graham Wheeler E-mail: gram@cdsec.com > Citadel Data Security Phone: +27(21)423-6065/6/7 > Firewalls/Virtual Private Networks Fax: +27(21)24-3656 > Internet/Intranet Network Specialists > Data Security Products WWW: > http://www.cdsec.com/ > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message