Daniel B. [email protected]lid writes:
On Feb 18, 9:48 am, ts [email protected] wrote:
“D” == Daniel B. [email protected] writes:
Try it with
D> fh = File.open(‘flock_test.txt’, ‘w’)
fh = File.open(‘flock_test.txt’, ‘w+’)
(I no longer have access to a Solaris machine, so I’m assuming in
my response here that Solaris does require write access for this.)
Yes, that worked. Do Solaris and Linux have different rules regarding
shared file locks? Or is that a bug?
It would appear that Solaris and Linux do, in fact, have different
rules. It’s a bug if you want it to be a bug!
The problem here is that there is no controlling authority. The
flock procedure is not part of the POSIX/UNIX standard. It was,
I believe, created as part of BSD 4.2, and like much non-standardized
software, its documentation is rather loose and the function is
mostly defined by its implementation.
The procedure is defined as part of the Linux standard, but the
documentation there is really just an abstraction of the man page.
Neither the Linux standard nor the BSD documentation specifies
what access (if any) is needed to take a lock (via flock) on a
file. And, of course, Solaris is not bound by the Linux standard.
The “obvious” way to implement flock on a POSIX system is to use
the locking facilities of fcntl(2). But, in that case the POSIX
standard requires that the file descriptor have read access for
shared access. (It is likely that ruby translated the ‘w’ access
to write-only access, which does not include read access). It
sounds like Solaris may have taken that path. (There are other
more subtle differences between the behavior of BSD flock and POSIX
fcntl, but that’s not relevant here.)
Given that the Solaris implementation differs from the original,
presumably defining, BSD implementation, you might report the
problem to Sun to get its view. On the other hand, since flock
has existed in the Solaris system for 15+ years now, I suspect
that the Solaris implementors know about its behavior – and lack
of correspondence to the BSD version. (One could argue that there
is a denial-of-access security issue associated with the BSD/Linux
In any case, right now Ruby seems to just use the OS’s flock
function, and I don’t think that it would be reasonable for the
Ruby implementation to attempt to get around this as it would be
far too messy – and slow. I’d just live with the problem.