procmail
[Top] [All Lists]

Re: what does this mean: "cannot execute binary file"?

2006-04-30 10:50:12
On Sun, Apr 16, 2006 at 09:24:37PM -0700, Bart Schaefer wrote:

On 4/13/06, TjL <lists(_at_)tntluoma(_dot_)com> wrote:

What is the easiest way to test for whether or not a directory
exists [. . .]?

# MAILDIR is set to a single dot when the chdir fails.
MAILDIR = $HOME
:0
* MAILDIR ?? [.]


I've been saving this until I had time to think about it fully and
compare it to the system I've been using.  This is better.  It's
very clever!  Thank you, Bart.  I've implemented this in my
own stuff now.

I had been using something I also thought was clever.  My
algorithm until now has been to try to save to

  $target/../`basename $target`

(with the `basename $target` thing ascertained, however, in
procmail only, with no shell calls).

The first person I knew of on this list to have talked about
that was David Tamkin, so until and unless I hear otherwise,
I'll attribute the trick to him.  The point is, if $target
is a file rather than a dir, then the attempt won't work.
So then we can save again, this time with a lockfile.

Okay, a downside is that a write-error warning message shows up
in the log for targets that are files rather than dirs; another
is that the whole "$target/../`basename $target" thing shows up
in the log as $LASTFOLDER for legacy-style procmail dirs; and yet
another is that, for "flat" (mbox-style) filenames, one then has to
add a repeat of the final delivery recipe (now with a lockfile, of
course), so it looks kind of goofy in the rcfile.  But it works
fine, and I've been using it for over a year in production.

Your algorithm, Bart, tries to chdir instead of trying to deliver
to $LASTFOLDER as the test.  That's cleaner.  The error message for
the failed chdir attempt on flat files is not as ominous looking,
and there's no need to try delivery twice for files.  I've coded
this in now as a general approach, and it works nicely.

Verbose logs either way look kind of hairy, but non-verbose logs
look normal except for the error messages -- and the weird $LASTFOLDER
entry on procmail "legacy" dirs my way.  Here are full verbose log
samples for all three types of delivery (legacy dir, maildir, and
flat file) for both algorithms.  (I only haven't tried MH dirs, but
they'd work -- okay, I just coded that in and tried them too, on
Bart's way down below.)

Logs from my way:

1) procmail "legacy" dir ($ALOCK was set in algorithm, but not used):

  procmail: Matched ".procmail"
  procmail: Match on "()\/[^/]+^^"
  procmail: Assigning "ALOCK=:"
  procmail: Assigning 
"LASTFOLDER=/net/u/1/d/dman/.procmail/../.procmail/msg.iI0b"
  procmail: Opening "/net/u/1/d/dman/.procmail/../.procmail/msg.iI0b"
  procmail: Acquiring kernel-lock
  From foo(_at_)bar  Sun Apr 30 18:51:27 2006
    Folder: /net/u/1/d/dman/.procmail/../.procmail/msg.iI0b                  
5689
  

2) maildir target:

  procmail: No match on "()\/[^/]+^^"
  procmail: Assigning 
"LASTFOLDER=/net/u/1/d/dman/.procmail/new/1146416072.21385_0.panix5.panix.com"
  From foo(_at_)bar  Sun Apr 30 18:54:32 2006
    Folder: /net/u/1/d/dman/.procmail/new/1146416072.21385_0.panix5.pani     
5650 


3) flat-file target:

  procmail: Matched "target"
  procmail: Match on "()\/[^/]+^^"
  procmail: Assigning "ALOCK=:"
  procmail: Assigning "LASTFOLDER=target/../target"
  procmail: Opening "target/../target"
  procmail: Error while writing to "target/../target"
          [ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ugly!!]
  procmail: Locking "target.lock"
  procmail: Assigning "LASTFOLDER=target"
  procmail: Opening "target"
  procmail: Acquiring kernel-lock
  procmail: [26076] Sun Apr 30 18:56:22 2006
  procmail: Unlocking "target.lock"
  From foo(_at_)bar  Sun Apr 30 18:56:21 2006
    Folder: target                                                           
5689


Logs from Bart's way (now also my way):

1) procmail "legacy" dir:

  procmail: Assigning "ALOCK"
  procmail: Match on ! "/^^"
  procmail: Match on ! "^^$MAILDIR^^"
  procmail: Match on ! "^^[.]^^"
  procmail: Assigning "MAILDIR_OLD=."
  procmail: Assigning "MAILDIR=/net/u/1/d/dman/.procmail"
  procmail: No match on "^^[.]^^"
  procmail: Assigning "MAILDIR=."
  procmail: Assigning "LASTFOLDER=/net/u/1/d/dman/.procmail/msg.rI0b"
  procmail: Opening "/net/u/1/d/dman/.procmail/msg.rI0b"
  procmail: Acquiring kernel-lock
  From foo(_at_)bar  Sun Apr 30 19:03:10 2006
    Folder: /net/u/1/d/dman/.procmail/msg.rI0b                               
5689
  

2) maildir target:

  procmail: Assigning "ALOCK"
  procmail: No match on ! "/^^"
  procmail: Assigning 
"LASTFOLDER=/net/u/1/d/dman/.procmail/new/1146416705.29766_0.panix5.panix.com"
  From foo(_at_)bar  Sun Apr 30 19:05:05 2006
    Folder: /net/u/1/d/dman/.procmail/new/1146416705.29766_0.panix5.pani     
5650


3) flat-file target:

  procmail: Assigning "ALOCK"
  procmail: Match on ! "/^^"
  procmail: Match on ! "^^$MAILDIR^^"
  procmail: Match on ! "^^[.]^^"
  procmail: Assigning "MAILDIR_OLD=."
  procmail: Assigning "MAILDIR=target"
  procmail: Couldn't chdir to "target"
         [  ^^^^^^^^^^^^^^^^^^^^^^^^^   okay, it's an error message, but not as 
scary]
  procmail: Assigning "MAILDIR=."
  procmail: Match on "^^[.]^^"
  procmail: Assigning "ALOCK=:"
  procmail: Assigning "MAILDIR=."
  procmail: Locking "target.lock"
  procmail: Assigning "LASTFOLDER=target"
  procmail: Opening "target"
  procmail: Acquiring kernel-lock
  procmail: [28264] Sun Apr 30 19:07:25 2006
  procmail: Unlocking "target.lock"
  From foo(_at_)bar  Sun Apr 30 19:07:24 2006
    Folder: target  


4) (addendum) MH-style folders:

  procmail: Assigning "ALOCK"
  procmail: Match on ! "/[.]?^^"
  procmail: Match on ! "^^$\MAILDIR^^"
  procmail: Match on ! "^^[.]^^"
  procmail: Assigning "_MAILDIR=."
  procmail: Assigning "MAILDIR=/net/u/1/d/dman/.procmail/."
  procmail: No match on "^^[.]^^"
  procmail: Assigning "MAILDIR=."
  procmail: Assigning "LASTFOLDER=/net/u/1/d/dman/.procmail/4"
  procmail: Opening "/net/u/1/d/dman/.procmail/4"
  procmail: Acquiring kernel-lock
  From foo(_at_)bar  Sun Apr 30 19:31:57 2006
    Folder: /net/u/1/d/dman/.procmail/4                                      
5689
  
---------------------------------------


Okay, here's my plug-in algorithm.  You set MYDELIVERY to your target
for delivery, be it a file or a dir, be it maildir, legacy-style, or
MH:

   ------------------------ delivery snippet from rcfile 
----------------------- 

   # MYDELIVERY should be set before we get here!!!!

   MYDELIVERY = ${MYDELIVERY:-$DEFAULT}

   ALOCK                                         # initialize ALOCK unset
   :0                                            # if target not known to be dir
   * ! MYDELIVERY ?? /[.]?^^
   * ! MYDELIVERY ?? ^^$\MAILDIR^^
   * ! MYDELIVERY ?? ^^[.]^^
   {
      MAILDIR_OLD = $MAILDIR                     # bucket holding current value
      MAILDIR = $MYDELIVERY                      # try to chdir
  
      :0                                         # if MYDELIVERY is a file ...
      *  MAILDIR ?? ^^[.]^^
      { ALOCK = : }                              # ... ALOCK gets set
  
      MAILDIR = $MAILDIR_OLD                     # go back whence we came
   }
  
   :0 $ALOCK                                     # ALOCK's unset for dirs
   $MYDELIVERY                                   # ... save to file or dir

   ------------------------ delivery snippet from rcfile 
----------------------- 


Dallman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail