Subject: Re: TRAP lockfiles

From: "Michael J. Corrigan" <[email-masked]>
Date: Wed, 11 Jan 1995 01:38:16 -0800

> 
> Is it possible to put a lockfile on the execution of the contents of
> the TRAP variable?  Or, alternately, is there a better way to update

The way I see it, using the TRAP variable is not good for
this purpose because for example, say an instance of procmail
creates folder message #8 and then exits and the TRAP process
locks the db.  While it has the lock, say 2 more instances of procmail
deliver messages #9 and #10, exit and their TRAP processes wait
on the lock held for message #8.  Then when the process for 
#8 releases the lock, the processes for #9 and #10 are
equally likely to acquire the lock and if #10 acquires the
new lock before #9, then #9 will be the last to update
the db and will you'll have the wrong last message number 
in the database.

You can lock the delivery and db manipulation together to avoid
this problem, i.e. so there can't be delivery without db update.
Maybe a global lockfile for all the recipes that access the db.
Like so:

LOCKFILE=active

:0
folder/.
...
:0
folderN/.

VBL=`$MAILDIR/add-active $LASTFOLDER`

LOCKFILE

Of course you can still get the later of two nearby-in-time
messages acquiring the lock just as before but your last
received folder message number will be correct.

> an "active" file that contains the last numbered file (MH-style) for
> each folder than:
> 
> TRAP='$MAILDIR/add-active $LASTFOLDER'
> 
> where add-active is a script that parses LASTFOLDER, then updates a
> file with the new count.
> 
> -- 
> Joe Hildebrand                  Fuentez Systems Concepts
> [email-masked]              11781 Lee-Jackson Hwy, Suite 700
> Senior Software Engineer        Fairfax, VA 22033
>                                 Phone:    (703)273-1447   
>                                 Fax:      (703)273-2972
>                                 PGPprint: 0x06C96661
> 
> Standard disclaimers apply
> 
>

---

From: Joe Hildebrand <[email-masked]>
Date: Wed, 11 Jan 1995 09:18:32 -0500

I wrote:

   Joe> Is it possible to put a lockfile on the execution of the
   Joe> contents of the TRAP variable?  Or, alternately, is there a
   Joe> better way to update

> "Michael" == Michael J Corrigan <[email-masked]> writes:

   Michael> You can lock the delivery and db manipulation together to
   Michael> avoid this problem, i.e. so there can't be delivery
   Michael> without db update.  Maybe a global lockfile for all the
   Michael> recipes that access the db.  Like so:

   Michael> LOCKFILE=active
   Michael> 
   Michael> :0
   Michael> folder/.
   Michael> ...
   Michael> :0
   Michael> folderN/.
   Michael> 
   Michael> VBL=`$MAILDIR/add-active $LASTFOLDER`
   Michael> 
   Michael> LOCKFILE

Doesn't processing of the .procmailrc file end when mail is delivered
to a script that doesn't have a 'c' flag?  I could add a call to
add-active for each recipe, but that seems extreme.  It may be the
only way to handle the case that a mail is delivered to multiple mail
boxes, however.