public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16285] New: thread-safe file locking (using lock file)
@ 2013-12-02 21:53 wolfgang at contre dot com
  2013-12-03  0:41 ` [Bug libc/16285] " bugdal at aerifal dot cx
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: wolfgang at contre dot com @ 2013-12-02 21:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16285

            Bug ID: 16285
           Summary: thread-safe file locking (using lock file)
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: wolfgang at contre dot com
                CC: drepper.fsp at gmail dot com

As you know, lockf, flock and fcntl are not useful to guarantee the ownership
of a lock for an unexisting file. To my knowledge, the only way to guarantee
that a yet-to-be-created file is properly locked beforehand is by using the
O_CREAT flag with "open". Then, a dead lock problem occurs if this is performed
on the original file, as there would be a priori no way to know if an existing
file is actually being created or if its creator process died, thereby leading
to a dead lock. One possibility is thus to use a separate specific lockfile
containing the pid ot the tid of the calling thread, which could then be
checked for "staleness" by other threads by writing the active pid/tid to it
and checking it back. Now, the problem with this approach is that if the file
is checked by two simultaneous processes and that they both attempt to acquire
it, there is no way to ensure that one of them would not unlink the version
just created by the other process. This, in turn, causes a race condition over
the lock file, which takes us back to our original problem.

What I think is that a correct way to avoid deadlocking would be if the kernel
could somehow guarantee that a file could be unlinked from the filesystem as
soon as it is closed or if it's creator process terminates (which would also
imply the former). I would thus propose a "O_UNLINK" flag to "open" which would
allow that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-06-13 11:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-02 21:53 [Bug libc/16285] New: thread-safe file locking (using lock file) wolfgang at contre dot com
2013-12-03  0:41 ` [Bug libc/16285] " bugdal at aerifal dot cx
2013-12-03  3:52 ` wolfgang at contre dot com
2013-12-03  4:04 ` bugdal at aerifal dot cx
2013-12-03 13:17 ` wolfgang at contre dot com
2013-12-03 13:26 ` wolfgang at contre dot com
2013-12-03 17:51 ` bugdal at aerifal dot cx
2013-12-22 18:27 ` carmelo73 at gmail dot com
2014-01-10 23:33 ` neleai at seznam dot cz
2014-01-11  6:08 ` wolfgang at contre dot com
2014-01-11 11:37 ` neleai at seznam dot cz
2014-06-13 11:50 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).