procmail
[Top] [All Lists]

Re: lock files

2000-02-15 07:35:28
On 15 February 2000, era eriksson <era(_at_)iki(_dot_)fi> wrote:
[...]
Somebody with a better grasp of the history of Procmail and/or Unix
implementations could do well to attempt to explain why there are
three different system calls and why you'd want to avoid using some of
them some of the time.

    Not to imply that I actually know something about the history of
Procmail or Unix, but AFAIK lockf(2) and fcntl(2) come from SVr2, while
flock(2) was introduced by BSD.  fcntl(2) is NFS-resistant (lockf(2)
and flock(2) are not), and that's one of the reasons it was blessed
by POSIX.  fcntl(2) didn't become popular until recent though, because
it tends to be pretty slow and because BSD didn't have it until 4.3
Reno.  This situation lead some vendors to develop their own proprietary
locking methods which are NFS-resistant and somewhat faster.

    SVr3 also added mandatory locking.  They don't have a special API,
files that are to use this method are marked by a special combination of
permission bits (group-id set, group execute unset).  As the name says,
they are mandatory, but since you can unlink(2) such a file there are
still way to circumvent them under some conditions.  On some systems
they also provide an excellent way to hang the machine hard under
certain conditions.

    Now, about why would you want to avoid some methods: fcntl(2), like
I said, is *slow*, so you don't want to use it unless you absolutely
have to (f.i. if you don't use NFS).  On some systems (f.i. Linux with
fairly old kernels) mixing some of these methods may hang the machine,
while on others they may resolve to the same system call, so you won't
be able to use more than one of them with the same file.  On other
(older) systems the underlying system calls might do nothing at all.
And so on --- basically, locks are almost as big a PITA as tty lines.
For mail, use Maildir if you can afford it, since it doesn't need any
kind of locking.

    Regards,

    Liviu Daia

-- 
Dr. Liviu Daia               e-mail:   Liviu(_dot_)Daia(_at_)imar(_dot_)ro
Institute of Mathematics     web page: http://www.imar.ro/~daia
of the Romanian Academy      PGP key:  http://www.imar.ro/~daia/daia.asc

<Prev in Thread] Current Thread [Next in Thread>