[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: flock() and sendmail



On Thu, Nov 16, 2006 at 11:24:34AM -0800, Richard A Nelson wrote:
> On Thu, 16 Nov 2006, John Kelly wrote:
> 
> >I don't need NFS with sendmail.  Surely flock() is not *still* broken
> >in 2.6 kernels?
> 
> I doubt that flock is *still* broken - that was quite some time ago...

>From the flock manpage:
NOTES
       flock(2) does not lock files over NFS.  Use fcntl(2) instead: that does
       work over NFS, given a sufficiently  recent  version  of  Linux  and  a
       server which supports locking.

The reason flock() doesn't work over NFS probably has to do with
that flock() and fcntl() locks don't interact with each other.

> >**  NOTE: Override HASFLOCK as you will but, as of 1.99.6, mixed-style
> >**      file locking is no longer allowed.  In particular, make sure
> >**      your DBM library and sendmail are both using either flock(2)
> >**      *or* fcntl(2) file locking, but not both.
> 
> This, indeed, is the important part !  DB has changed alot, and now
> has its own locking system, and whatever it uses to lock the entire
> DB is what should be used by its callers.
> 
> Has DB changed from fcntl to flock ?
> Are you trying to access the sendmail databases from another
> program that has differing locking conventions ?
> 
> You fail to provide any hints as to on why fcntl which is used instead
> of flock is causing you grief.

If sendmail is using libdb, I don't see why sendmail would need to
use fcntl() or flock() on any libdb file.  It's an internal problem
of libdb how it should do it's locking before it updates the database.

However, sendmail might want to make sure that it's only updating it
once, and can do this is various ways.

As long as sendmail properly uses libdb, I don't see why there should
be any problem at all.


Anyway, from the linux/Documentation/locks.txt file:
1.2.1 Typical Problems - Sendmail
---------------------------------
Because sendmail was unable to use the old flock() emulation, many sendmail
installations use fcntl() instead of flock(). This is true of Slackware 3.0
for example. This gave rise to some other subtle problems if sendmail was
configured to rebuild the alias file. Sendmail tried to lock the aliases.dir
file with fcntl() at the same time as the GDBM routines tried to lock this
file with flock(). With pre 1.3.96 kernels this could result in deadlocks that,
over time, or under a very heavy mail load, would eventually cause the kernel
to lock solid with deadlocked processes.



Kurt



Reply to: