procmail
[Top] [All Lists]

Re: [Q] When to use lock files?

1996-10-16 18:29:44
Robby Lee <rylee(_at_)CSUPomona(_dot_)Edu> writes:

To my understanding, is it correct that lock files should be
used only for filtering? Otherwise it's unnecessary?

:0
^to_john
!john(_at_)abc(_dot_)com

:0:local.lock
| formail -I"Subject: [Test]"

That should probably be:

:0fh
| formail -I"Subject: [Test]"


      ??? Please clarify.  Thanks.

Lockfiles are only needed when procmail is doing something that should
be serialized, i.e., when only one process at a time should be doing it.

This generally means that any time you write to a file, you should have
a locallock, preferably based on the name of the file being written to.
Forwarding actions ('!'), and 99% of all filters don't need lockfiles.
However, if a filter action writes to a file while filtering, then you
may need a lock.  To demonstrate this rule, consider the recipe above:
it doesn't need a lockfile because no file was written to, and multiple
formails can run at once.  However, the following recipe does need one:


:0fh:tempfile.lock
| cat >tempfile; formail -I"Subject: [Test]" < tempfile; rm -f tempfile

This recipe does the exact same thing as the previous one, but it's slower,
more prone to error, requires diskspace to run, and (the key point here)
requires a lockfile to prevent one procmail from overwriting tempfile
while another is still running the action.

Does that clear things up, or have I just made it worse?

Philip Guenther