On Mon, Jun 04, 2001 at 05:47:57PM -0400, Scott McDermott wrote:
> Homer Wilson Smith on Mon 4/06 14:20 -0400:
> > Using perl5.x what is the proper way to lock a mailbox so that
> > popper nor procmail won't touch it and there is no chance of a
> > race condition?
>
> probably the fcntl() equivalent.
Answers may vary depending on your UNIX flavor, and the type of volume
you are dealing with. On some system it's still "dot-lock", or IIRC
fcntl or flock() may be implemented as a "dot-lock". I believe part of
the procmail configure/install (though it's been a while since I ran
it) is a utility which tests a specified volume on your system and
determines the best locking method to use on your system. I would go
with what it says.
Procmail also generates a standalone utility, "lockfile" (man 1
lockfile) which can be executed for locking. We use this for some
cron-driven scripts here, as part of more complex mutual exclusion
shell code.
> But keep in mind that all bets are off
> if you're running server mode because they unlock in the middle of the
> session.
So you simply need to make sure, first, that a server mode pop session
isn't already running for that file and that one can't start.
I think the proper procedure looks something like this:
disable pop login for account (e.g. via the qpopper 4 nonauth-file
mechanism or by changing account password)
while ( check if qpopper is running for that account ) {
wait;
}
/* pop process completed OK */
while (attempt to lock mailbox fails) {
wait;
}
/* got the lock */
update file;
unlock mailbox;
re-enable pop login.
-- Clifton
--
Clifton Royston -- LavaNet Systems Architect -- [EMAIL PROTECTED]
WWJD? "JWRTFM!" - Scott Dorsey (kludge) "JWG" - Eddie Aikau