[brandz-discuss] flock LOCK_EX vs. open O_RDONLY

Nils Nieuwejaar nils.nieuwejaar at Sun.COM
Wed Jun 13 08:09:43 PDT 2007


On Wed 06/13/07 at 16:45 PM, Martin.Man at Sun.COM wrote:
> Hi all,
> 
> according to
> http://mail.opensolaris.org/pipermail/brandz-discuss/2006-March/000863.html
> 
> it seems that flock with LOCK_EX called on top of a file opened with
> O_RDONLY will return EBADF in a lx brand.
> 
> I'm hitting this problem with the latest nevada build and lx brandz
> running a copy of debian in it and I have been able to work around the
> problem by simply adding O_RDWR to the problematic open(2).
> 
> I'm however not sure who is the buggy part here? brandz emulation of
> flock or code that uses LOCK_EX with O_RDONLY ??

Neither is buggy, but the code was written using non-portable interfaces.
flock() is a non-standard interface, and Linux and Solaris have different
semantics for it.  Portable code should use fcntl().

Even though BrandZ is all about smoothing over the semantic differences
between Solaris and Linux, this particular difference is very hard to work
around.  Actually, it would probably be more accurate to say that fixing it
would be fairly easy, but very invasive to core Solaris.

> bug reported ? fix pending ?

6318648 flock() should be able to place a shared or exclusive lock
	regardless of the open mode

This bug has been open for just over a year, and I don't expect it to be
closed any time soon - if ever.  It's unfortunate that we can't get this
call exactly right, but so far we don't have the justification we need to
perform the necessary surgery on Solaris.

Nils



More information about the brandz-discuss mailing list