Philip Guenther caught a bug in my suggestion to Jason Carroll:
| Assuming that $ORGMAIL == $DEFAULT, the above will lead to deadlock
| when procmail tries to do the implicit delivery to $DEFAULT as it'll
| try to lock $DEFAULT$LOCKEXT, and hang on it until it decides the lock
| is stale.
Thanks for spotting that, Philip. Unfortunately, it looks as though you've
allowed me an opportunity to return the favor.
| # Try locking $DEFAULT with no retries:
| :0
| * ? lockfile -r0 $DEFAULT$LOCKEXT
| {
| # Attempt delivery
| :0 c
| $DEFAULT
|
| # On success, cleanup the lock and exit
| :0 ai
| |rm -f $DEFAULT$LOCKEXT
| }
Unfortunately, nothing removes $DEFAULT$LOCKEXT if the lock was acquired but
the save failed.
| # Dang, it didn't work. If $ORGMAIL != $DEFAULT then try ORGMAIL
| :0
| * ! ORGMAIL ?? ^^$\DEFAULT^^
| * ? lockfile -r0 $ORGMAIL$LOCKEXT
| {
| # Attempt delivery
| :0 c
| $ORGMAIL
|
| # On success, cleanup the lock and exit
| :0 ai
| |rm -f $ORGMAIL$LOCKEXT
| }
|
| # Okay, we couldn't deliver to either $DEFAULT or $DEFAULT.
| # Give up and throw EX_TEMPFAIL
| EXITCODE = 75
| HOST
And again, if it got that far, nothing removes $ORGMAIL$LOCKEXT if the
lock was acquired but the save failed.
So let's try tweak that in.
# Try locking $DEFAULT with no retries:
:0
* ? lockfile -r0 $DEFAULT$LOCKEXT
{
# Attempt delivery
:0 c
$DEFAULT
:0 e # record results of save attempt
{ FAILED=yes }
# On success, clean up the lock and exit
# On failure, clean up the lock and keep trying
:0 i${FAILED+c}
|rm -f $DEFAULT$LOCKEXT
}
# Dang, it didn't work. If $ORGMAIL != $DEFAULT then try ORGMAIL
:0
* ! ORGMAIL ?? ^^$\DEFAULT^^
* ? lockfile -r0 $ORGMAIL$LOCKEXT
{
# Attempt delivery
:0 c
$ORGMAIL
:0 e # record result of desperation attempt
{ FAILED_AGAIN=yes }
# On success, clean up the lock and exit
# On failure, clean up the lock, requeue, and bail
:0 i${FAILED_AGAIN:+c}
|rm -f $ORGMAIL$LOCKEXT
}
# Okay, we couldn't deliver to either $DEFAULT or $DEFAULT.
# Give up and throw EX_TEMPFAIL
EXITCODE = 75
HOST
Some of you may prefer the perkier approach of recording successes rather
than failures. OK then ...
# Try locking $DEFAULT with no retries:
:0
* ? lockfile -r0 $DEFAULT$LOCKEXT
{
# Attempt delivery
:0 c
$DEFAULT
:0 a # record results of save attempt
{ SUCCEEDED=H } # H, B, or D would be non-null and harmless
# On success, clean up the lock and exit
# On failure, clean up the lock and keep trying
:0 i${SUCCEEDED:-c}
|rm -f $DEFAULT$LOCKEXT
}
# Dang, it didn't work. If $ORGMAIL != $DEFAULT then try ORGMAIL
:0
* ! ORGMAIL ?? ^^$\DEFAULT^^
* ? lockfile -r0 $ORGMAIL$LOCKEXT
{
# Attempt delivery
:0 c
$ORGMAIL
:0 e # record result of desperation attempt
{ SUCCESS_AT_LAST=B }
# On success, clean up the lock and exit
# On failure, clean up the lock, requeue, and bail
:0 i${SUCCESS_AT_LAST:-c}
|rm -f $ORGMAIL$LOCKEXT
}
# Okay, we couldn't deliver to either $DEFAULT or $DEFAULT.
# Give up and throw EX_TEMPFAIL
EXITCODE = 75
HOST