Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Apr 1999 15:05:41 +0200
From:      Ladavac Marino <mladavac@metropolitan.at>
To:        'Graham Wheeler' <gram@cdsec.com>, hackers@freebsd.org
Subject:   RE: File locking problem
Message-ID:  <55586E7391ACD211B9730000C11002761795EE@r-lmh-wi-100.corpnet.at>

next in thread | raw e-mail | index | archive | help
> -----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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?55586E7391ACD211B9730000C11002761795EE>