Closed GoogleCodeExporter closed 9 years ago
This
ScopedFileHandle handle(HANDLE_EINTR(
open(file_path(), O_RDWR | O_EXLOCK | O_CREAT)));
will just fail (not block) if the file's already locked, right?
Original comment by scottmg@chromium.org
on 10 Mar 2015 at 5:35
No, that will block. O_NONBLOCK would be required to make it non-blocking and
return EAGAIN if it were already locked.
Original comment by rsesek@chromium.org
on 10 Mar 2015 at 5:40
I see, thanks.
Looking into it a bit more, I'm leaning towards implementing Lock/Unlock in
file_io.h. Windows doesn't have the ability to atomically do a LockFileEx in
the CreateFile call (it can open exclusively/lock, but can't have CreateFile
block until the lock is released).
It seems the O_EXLOCK and O_SHLOCK don't exist on Linux either at least
according to `man 2 open` on my box. Not a consideration now, but presumably
will be in the future. (?)
Does that seem reasonable? i.e. switching to separate flock-ish calls?
Original comment by scottmg@chromium.org
on 11 Mar 2015 at 12:00
Original comment by mark@chromium.org
on 11 Mar 2015 at 4:11
That should be fine. The only tricky bit is the O_EXCL|O_CREAT in Initialize,
which could then be raced since the O_EXLOCK won't be taken at the same point.
Otherwise, it should be fine to split open() and flock().
Original comment by rsesek@chromium.org
on 11 Mar 2015 at 10:24
Original comment by scottmg@chromium.org
on 1 May 2015 at 10:10
Original issue reported on code.google.com by
rsesek@chromium.org
on 9 Mar 2015 at 6:18