On Thu, Dec 20, 2001 at 11:10:03PM +0100, Mark wrote:
> Dear folks,
> 
> I have a question about Qpopper's locking mechanism (3.x). I have a Perl LDA
> on my FreeBSD 4.1.1 box, in which I use an exclusive flock to lock a user
> mailbox before writing to it. I always thought qpopper honors the same
> flock, and will not truncate on the user's mailbox until it can acquire a
> lock. But since I suspect to have lost some mail, I want to be sure now.

Hi, Mark!

  The normal behavior for Qpopper, in accessing the user mailspool, is
to follow the default lock convention for mail delivery programs, which
for historical reasons is user.lock in the mail spool directory.  When
it needs exclusive access to the spool Qpopper will attempt to create
the user.lock file in an "atomic" fashion, then lock it exclusively
with flock, and write its own pid to it.  (This last is a bit more
extensive than what many lock methods will do, but in general, creating
user.lock in an exclusive way is the requirement.)


> I know that (additionally?) qpopper uses the .user.lock and user.lock file.

  For mail spool, unless you've changed it, qpopper should *only* be
using user.lock in the spool directory.

  So yes, it is quite possible you're losing mail if your approach is
what you describe.  Sorry. :-/  On the bright side, it sounds like
you've correctly identified the reason.


> Should I try and emulate that, or will an flock on mbox suffice? Basically,
> all I need to know is which one should I set to prevent qpopper from writing
> and/or truncating mbox.

  Create user.lock in an atomic way (e.g. by creating a different file
and relinking it to user.lock, or by opening it with O_CREAT|O_EXCL if
you trust them) and if feasible flock it too, then reverse those steps
at the end to unlock it.  "man open" and "man flock", also read
common/maillock.h in the qpopper sources.

  The "lockfile" utility included with procmail does a good job for
mail locks, and is also a good starting point for understanding the
locking mechanism.

  Since I'm making some very specific assertions here, that should draw
out any needed corrections on any point I've got wrong. :-) 

  -- Clifton

-- 
 Clifton Royston  --  LavaNet Systems Architect --  [EMAIL PROTECTED]
   WWJD?   "JWRTFM!" - Scott Dorsey (kludge)   "JWG" - Eddie Aikau

Reply via email to