procmail
[Top] [All Lists]

How can I catch a TIMEOUT as an error?

1998-01-22 13:48:11
Gentlefolks,

    I want to fire off a process to handle `bot' request but am having
    trouble catching possible errors.  Here is the relevant section of the
    rcfile I'm developing:

:0
* ^To(.*\.bot)
{
     LOG="Final: Processing bot request;
"
     :0 c
     $RQSTFLDR

     TIMEOUT=300                                # Kill dispatcher if it runs
                                                #   for more than 5 minutes.
     :0 w
     * ? $DISPATCHER  "$BOTNAME"  "$CMDFROM"  "$CMDLINE"
     $DONEFLDR

     #------------------------------------------+
     # If we fall through there must have been  |
     # a problem.                               |
     #------------------------------------------+

     :0 c
     $FAILFLDR

     :0 fhw
     | formail -I"From: $WHOAMI acting as <$BOTNAME>" \
               -I"To: $ADMIN" \
               -I"Subject: Bot error! See $LOGFILE on $HOST" \
               -I"Reply-to: $PANIC" \
               -a"X-From: $CMDFROM" \
               -a"X-Subj: $CMDLINE"; \
               echo "Failed request from: $CMDFROM"; \
               echo "            Subject: $CMDLINE"; \
               echo "- - -"

     :0
     ! $ADMIN
}


    If the "$DISPATCHER" program (a Perl script) exits with an error, this
    does what I want -- i.e. files the message in the $FAILFLDR folder and
    sends a nasty gram to the admin.  But if I simulate a timeout (by
    having the program sleep past the limit), as the documentations says:

         "The offending program will receive a TERMINATE signal 
         from procmail, and processing of the rcfile will
         continue."

    I had hoped that meant `continue at the next rule', but what happens is
    that the message is filed in the $DONEFLDR and is considered delivered.
    I tried trapping the TERM signal in the script and forcing an error
    exit (die), but that didn't do it either; the program's exit message
    makes it to the log, but the delivery is still completed to the
    $DONEFLDR and stops there.

    No doubt there is a better way of doing this, which is: to receive
    notification if my script dies or hangs for any reason.  Any
    suggestions on how?

    Thanks in advance....

                                                        Later.....BC

    PS: I considered having my script, when it traps the signal, send the
        e-mail message itself, but the camel book warns against doing
        anything too fancy since on most systems the C library is not
        re-entrant (P 338).  It also seems like this would best be handled
        by procmail.

-- 
##    ##    ##    ## +----------------------------[ 
Bill(_dot_)Costa(_at_)UNH(_dot_)EDU ]---+
##    ###   ##    ## | Bill Costa                                          |
##    ####  ##    ## | CIS - Kingsbury Hall                                |
##    ## ## ######## | 33 College Road              PHONE: +1-603-862-3056 |
##    ##  ####    ## | University of New Hampshire    FAX: +1-603-862-4778 |
##    ##   ###    ## | Durham, NH  03824-3591  USA                         |
 #######    ##    ## +----------------[ No good deed goes un-punished. ]---+

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