procmail
[Top] [All Lists]

Re: A potential locking problem

1998-12-02 18:01:47
Matthew Saroff wrote,

|       I have the following recipe:
| #puts body of email through program looks up numbers
| :0bc:tpc.lock
| *   ^Subject:[  ]checktpc
| * ! ^X-Loop: msaroff(_at_)pca\(_dot_)net
| TPC=|$HOME/tpcrun;
| 
| #mail results back to person
| :0ac:tpc.lock
| | (formail -r \
| -A "X-Loop: msaroff(_at_)pca(_dot_)net" \
| -A "Precedence: junk" \
| -I "Subject: Your TPC Number Validation"; \
| echo "$TPC";) | $SENDMAIL -t -oi
| 
|       It strikes me that there has to be a better way to set this up to
| eliminate the "space" between the two locks. Any suggestions?

In other words, you want a single hold on the lock to cover both recipes?
Normally that is done with what we call a regional lockfile (same syntax
as a global lockfile, except it exists briefly, usually within a braced
block, and is released when no longer needed).

However, I don't see any reason to have a local lockfile on the second
recipe.  It does not write to any files.  So while my specific advice
for this case is not to lock the second recipe at all, here is how you
can put one lock on both with a regional lockfile (additionally, I'd
recommend the `w' or `W' flag on the call to $HOME/tpcrun; otherwise procmail
will base its notion of success on whether $HOME/tpcrun accepted the input
rather than on tpcrun's exit code, and one semicolon is enough on the recipe
that runs formail and echo):

  :0
  *   ^Subject:[  ]checktpc
  * ! ^X-Loop: msaroff(_at_)pca\(_dot_)net
  {
   LOCKFILE=tpc.lock

   :0bw # `c' is superfluous on variable capture recipes
   TPC=|$HOME/tpcrun;
 
   #mail results back to person
   :0ac # regional lockfile is still in effect
   | (formail -r \
    -A "X-Loop: msaroff(_at_)pca(_dot_)net" \
    -A "Precedence: junk" \
    -I "Subject: Your TPC Number Validation"; \
    echo "$TPC") | $SENDMAIL -t -oi
 
   LOCKFILE # release regional lock
  }

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