procmail
[Top] [All Lists]

Re: TRAP, exit codes, etc.

2004-04-14 15:27:12
On 14 Apr, Dallman Ross wrote:
| On Wed, Apr 14, 2004 at 05:00:28PM +0100, Lars Hecking wrote:
| > 
| > [...]
| > 
| > > 
| > > However, David Tamkin asked me privately what I also was wondering
| > > after reading the procmail man pages (and procmailex has related stuff
| > > to say too); namely, what happens if in procmail we specify EXITCODE=0,
| > > but in TRAP we set it otherwise?  The man pages don't seem to
| > > discuss that, and I have no idea if it's a valid thing to want to do.
| > 
| >  Valid mail system exit codes are defined in <sysexits.h>. Legal values
| >  are 0 (EX_OK), and 64-79. Examination of the procmail source code will
| >  be required to find out what procmail does with EXITCODE values not
| >  covered by <sysexits.h>.
| 
| Okay, understood; but that still doesn't answer the question of
| what happens if procmail says the EXITCODE is 0 but TRAP says it's
| not zero.  Who wins?  Does the TRAP value get sent to the MTA,
| or just to the shell?

I haven't been able to follow the entire thread, but I don't think this
got any answers.  Excuse me if it did.

After running a handful of tests, all sending a message designed to 
trip a recipe from outside tradersdata.com to an address at
tradersdata.com, these are the results.

Setting EXITCODE = 1, generated a bounce (permanent failure) indicating
"unknown mailer error 1", but the message was delivered successfully.

Leaving EXITCODE alone and setting TRAP = 'false', resulted in the
message being delivered.  No bounce.

Setting EXITCODE="" and TRAP = 'false' was the same result as the first.

In summary, all three were delivered appropriately and the first and
third generated a bounce that reflected the EXITCODE = 1.

The reason for the third test was a re-read of the man page which
indicated if EXITCODE is set but empty, procmail will set it to whatever
the TRAP returns.  If EXITCODE has not been set, procmail will set it
to zero shortly before executing TRAP.  This is all confirmed in the
logs.

Second run (procmail sets EXITCODE=0, because it was previously unset):

procmail: [25267] Wed Apr 14 17:07:45 2004
procmail: Assigning "TRAP=false"
procmail: Locking "/var/spool/mail/deh.lock"
procmail: Assigning "LASTFOLDER=/var/spool/mail/deh"
procmail: Opening "/var/spool/mail/deh"
procmail: Acquiring kernel-lock
procmail: Unlocking "/var/spool/mail/deh.lock"
From ***(_at_)[redacted]  Wed Apr 14 17:07:44 2004
 Subject: B-B-B-o-o-o-i-i-i-n-n-n-g-g-g
  Folder: /var/spool/mail/deh                                              1457
procmail: Notified comsat: "deh(_at_)4610903:/var/spool/mail/deh"
procmail: Assigning "EXITCODE=0"
procmail: Executing "false"

Third run (EXITCODE="" before TRAP):

Caught B-B-B-o-o-o-i-i-i-n-n-n-g-g-g
procmail: [25449] Wed Apr 14 17:25:24 2004
procmail: Assigning "EXITCODE="
procmail: Assigning "TRAP=false"
procmail: Locking "/var/spool/mail/deh.lock"
procmail: Assigning "LASTFOLDER=/var/spool/mail/deh"
procmail: Opening "/var/spool/mail/deh"
procmail: Acquiring kernel-lock
procmail: Unlocking "/var/spool/mail/deh.lock"
From ***(_at_)[redacted]  Wed Apr 14 17:25:23 2004
 Subject: B-B-B-o-o-o-i-i-i-n-n-n-g-g-g
  Folder: /var/spool/mail/deh                                              1469
procmail: Notified comsat: "deh(_at_)4195383:/var/spool/mail/deh"
procmail: Executing "false"

I'm not sure what good this is since there's nothing in the log that
indicates TRAP did, in fact, effectively change the EXITCODE (although
the bounce proves it did).  I can't think of anyway to trap that
EXITCODE that wouldn't, at the same time, change it back to zero. 
Whether you can do anything with it is beyond me, but I think this
answers your question by showing that the TRAP exitcode is being sent
to the MTA.

If that's not exactly what you're looking for, let me know and I'll
modify it.

BTW, here's the recipe:

:0
* FROM ?? ***(_at_)[redacted]
* SUBJECT ?? ^^\/B-B-B-o-o-o-i-i-i-n-n-n-g-g-g^^
{
  LOG = "Caught $MATCH$NL"
  VERBOSE = yes
  EXITCODE=""
  TRAP = 'false'
  :0:
  $DEFAULT
}

Hope that helps.


-- 
A vote for Nader is a vote for George Bush?  Surely this won't trick
Bush supporters into voting for Nader. But, since Kerry's supporters
believe this deception, I wonder how many of them can be fooled into
voting for Bush.   Try this:  A vote for Bush is a vote for Kerry.



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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