From: Karel Zak <kzak@redhat.com>
To: Kjetil Torgrim Homme <kjetil.homme@redpill-linpro.com>
Cc: util-linux@vger.kernel.org
Subject: Re: flock(1): working with fcntl locks
Date: Sat, 4 Jan 2014 09:31:07 +0100 [thread overview]
Message-ID: <20140104083107.GB4435@x2.net.home> (raw)
In-Reply-To: <52C6D365.10601@redpill-linpro.com>
On Fri, Jan 03, 2014 at 04:12:37PM +0100, Kjetil Torgrim Homme wrote:
> > Welcome to POSIX/Linux locking... read nice Lennart's summary:
> > http://0pointer.de/blog/projects/locking.html
> > http://0pointer.de/blog/projects/locking2
>
> thanks! doesn't seem relevant for flock(1), though, since there is no
> threading involved. flock(1) should acquire the lock, fork the child and
> wait for it before returning the lock. no pitfalls there?
(
flock -n 9 || exit 1
# ... commands executed under lock ...
) 9>/var/lock/mylockfile
this is way how people use flock in scripts and it works because it's
based on file descriptors and independent on original process.
> I don't see why you think fcntl(2) sucks more.
see Lennart's summary, the problem is that the lock is based on
process and it's useless for system files (due to open/close
in libraries), etc.
> > No please, flock(1) is based on flock(2), that's all. The semantic
> > and all possible limitations are well known. I don't think we want to
> > make things more complicated.
>
> do you think we should have a posixlock(1)? (if so, perhaps it would fit
> better in coreutils rather than util-linux ...)
Yep.
Frankly, reliable fcntl locking requires a lot of code and extra lock
files (we use it for example in original mount for /etc/mtab).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2014-01-04 8:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-03 13:59 flock(1): working with fcntl locks Kjetil Torgrim Homme
2014-01-03 14:40 ` Karel Zak
2014-01-03 15:12 ` Kjetil Torgrim Homme
2014-01-04 8:31 ` Karel Zak [this message]
2014-01-10 20:46 ` Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140104083107.GB4435@x2.net.home \
--to=kzak@redhat.com \
--cc=kjetil.homme@redpill-linpro.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox