procmail
[Top] [All Lists]

Re: Counting rule and skip?

1996-08-28 16:46:33
Philip Guenther corrected my suggestion for Aaron Turner:

| It's a small point, but you should lock the counter file before the
| read and unlock it after the write.  Otherwise you have a race
| condition which could allow too many messages through.  To do this
| you'll want a global lockfile:

Good idea, Philip, but you didn't go far enough.

| SHELL = /bin/sh       # if your $SHELL is not Bourne shell for procmail,
|                       # change it at the top of your .procmailrc.  csh
|                       # is broken for programming!
| 
| :0
| * ^From(_dot_)*joe\(_dot_)blow(_at_)foo\(_dot_)com
| {
|     COUNTERFILE = path/to/counter/file
|     MAXTIMES = 9
| 
| 
|     # Lock it before the read
|     LOCKFILE=$COUNTERFILE.lock
| 
|     :0c:
|     * $ -`wc -l < $COUNTERFILE 2>&1 || echo 0`^0
|     * $ $MAXTIMES^0
|     JOE
|       :0Ahi # we're already locked via the global lockfile
|       | echo >> $COUNTERFILE
| 
|     :0Eh
|     /dev/null
| }

One further comment: below the dump to /dev/null, just before the closing
brace, you should unset LOCKFILE to remove the regional lockfile [I like to
call such a lockfile regional, rather than global, to distinguish it from one
that covers the entire .procmailrc and prevents any instantiation of procmail
from proceeding until the one that has the lock is completely finished] in
case an error on the echo action or on the dump to /dev/null makes procmail
fall through past the closing brace.  You could also clear it above the dump
to /dev/null.

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