Subject: Re: --with-locking-method
To: Brian A. Seklecki <lavalamp@spiritual-machines.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: tech-pkg
Date: 12/21/2002 11:23:19
On 21 Dec 2002, Brian A. Seklecki wrote:

> if an application's configure script offers a choice between the
> following functions:
>
> fcntl, lockf, flock
>
> ...which would be preferred?

NetBSD's fcntl(2) manual page suggests: "If an application wishes only to
do entire file locking, the flock(2) system call is much more efficient."

But Linux kernel Documentation/locks.txt:

"The solution I have chosen, after much experimentation and discussion, is
to make flock() and fcntl() locks oblivious to each other. ... The only
OS's that support cooperative flock()/fcntl() are those that emulate
flock() using fcntl(), with all the problems that implies."

So when locking with flock under Linux, you can't relock again with
fcntl. But you can do the reverse. So in other words, under Linux if you
use the fcntl to lock a mailbox (for example), then another program using
flock (on same mailbox) won't know and you may lose data.

So maybe the package should use fcntl for BSD, and under Linux use flock.

   Jeremy C. Reed
   http://bsd.reedmedia.net/