procmail
[Top] [All Lists]

Re: Procmail locking and timeouts

1998-09-02 16:02:14
"David W. Tamkin" <dattier(_at_)Mcs(_dot_)Net> writes:
...
The only way to do that would be with a global lockfile -- at least per
user, but not per destination folder.  Something like this:

:0 # try only once to get the lock; requeue and bail if we can't
* ! ? lockfile -r0 $ORGMAIL$LOCKEXT
{ EXITCODE=75
  HOST }

# If we have the lock, procmail does not know it as $LOCKFILE and will
# not automatically remove it on exit, so trick procmail into removing it:

TRAP="rm -f $ORGMAIL$LOCKEXT ${TRAP:+ ; $TRAP}"

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.

The solution to that is to not use the implicit delivery but write it
yourself without the locallockfile.  To make that work with user level
.procmailrcs you would have to phrase the /etc/procmailrc along the
following lines:

        DROPPRIVS = 1                   # middle-class, here we come!
        INCLUDERC = $HOME/.procmailrc   # try the user's .procmailrc

        # Okay, we fell through and should now deliver to $DEFAULT.
        # Just in case, we'll reset $PATH to something safeish.
        # Yes, we're running as the user, but we don't want to screw
        # up just because they removed /usr/local/bin from the path
        # and lockfile is there.  If you put lockfile somewhere else,
        # make sure you add that directory the following line.
        PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin

        # 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
        }

        # 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


Philip Guenther

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