Subject: Cygwin procmail patch (was Re: procmail locking problem warning)
From: Jason Tishler <[email-masked]>
To: Philip Guenther <[email-masked]>
Cc: Greg Matheson <[email-masked]>, [email-masked], Cygwin <[email-masked]>
Date: Thu, 04 Apr 2002 13:22:35 -0500

Philip,

On Fri, Mar 29, 2002 at 02:08:07PM -0600, Philip Guenther wrote:
> Greg Matheson <[email-masked]> writes:
> >My WAG is that procmail's autoconf is having problems with missing
> >".exe" strings in executable names during mv operations:
> >
> > [snip]
> 
> So, "make _autotst" actually creates the file _autotst.exe?  If so, the
> solution is to add a variable containing the executable file extension and
> scatter it throughout the Makefiles and the initmake and autoconf script.

See attached for a patch that solves the above and a few other Cygwin
issues.  Besides handling the ".exe" executable file extension issue,
this patch also handles the following:

    o Make the install target .PHONY so that make install works even
      if a file called "install" (or "INSTALL" under Cygwin) exists.
      Note that Cygwin (i.e., Windows) has a case-insensitive
      filesystem.
    o Add autoconf check for Cygwin to #define NO_COMSAT because Cygwin
      does not currently support endprotoent() and endservent().
    o Add __CYGWIN__ conditional compilation guard to an autoconf test
      to prevent PATH from being set such that the Cygwin DLL cannot
      found.
    o Add autoconf check for Cygwin's default "sendmail" -- ssmtp.

I tried this patch under Red Hat Linux 7.1 without any ill effects.
Would you be willing to accept this patch into procmail CVS?

With this patch Cygwin procmail can be built and installed as follows:

    $ make EXE=.exe LOCKINGTEST=100
    $ make EXE=.exe install

I would have liked to make the specification of EXE unnecessary but
I don't know how to do this in a make independent way.  Does procmail
support other makes?  Or, only GNU make?  If only GNU make, then I can
provide a patch to make the specification of EXE unnecessary.

Unfortunately even with this patch and many hours of head-banging, I
was not able to get autoconf to sense that Cygwin supports fcntl().
Hence, the hardwiring with "LOCKINGTEST=100" on the make command line.

I even adding the following to autoconf in the "right" spot:

    mkdir /tmp/autoconf.$$
    cp _autotst.c ../autoconf.h ../config.h _locktst.h /tmp/autoconf.$$

to catch the relevant autoconf test in the attempt to debug this problem.
I finally gave up when I couldn't get this code to run without errors
even under Linux!  It seems like this code only works when run from
autoconf which makes debugging difficult.

> Note that procmail always uses plain newline for line endings, never
> carriage-return newline.  If that's not compatibile with the other
> mail software on your platform, then procmail will not work for you.
> (Procmail doesn't use stdio, so its mapping doesn't come into play.)

The above is not an issue.  I have been using fetchmail/procmail/mutt
under Cygwin for about a year now and I have only had locking problems due
to a bad builds (i.e., procmail fcntl() and mutt dotlocking accidentally
disabled).

Thanks,
Jason
diff -upr procmail-3.22.orig/Makefile procmail-3.22/Makefile
--- procmail-3.22.orig/Makefile	Tue Sep 11 00:53:09 2001
+++ procmail-3.22/Makefile	Wed Apr  3 17:41:56 2002
@@ -97,6 +97,7 @@ LDFLAGS1= $(LDFLAGS0) $(LIBS) #-lcposix
 ####CC	= cc # gcc
 # object file extension
 O	= o
+EXE	=
 RM	= /bin/rm -f
 MV	= mv -f
 LN	= ln
@@ -107,7 +108,7 @@ STRIP	= strip
 MKDIRS	= new/mkinstalldirs
 
 SUBDIRS = src man
-BINSS	= procmail lockfile formail mailstat
+BINSS	= procmail$(EXE) lockfile$(EXE) formail$(EXE) mailstat
 MANS1S	= procmail formail lockfile
 MANS5S	= procmailrc procmailsc procmailex
 
diff -upr procmail-3.22.orig/Makefile.1 procmail-3.22/Makefile.1
--- procmail-3.22.orig/Makefile.1	Tue Sep 11 00:53:09 2001
+++ procmail-3.22/Makefile.1	Wed Apr  3 17:42:34 2002
@@ -9,6 +9,7 @@ make:
 	@$(SHELL) -c "exit 0"
 
 .PRECIOUS: Makefile
+.PHONY: install
 
 help target targets:
 	@sed "/^##*\*#$$/,/^##*\*#$$/ !d" <Makefile
diff -upr procmail-3.22.orig/src/Makefile.0 procmail-3.22/src/Makefile.0
--- procmail-3.22.orig/src/Makefile.0	Thu Jun 28 22:20:35 2001
+++ procmail-3.22/src/Makefile.0	Wed Apr  3 17:41:56 2002
@@ -17,16 +17,16 @@ make:							# fake target
 
 .PRECIOUS: Makefile
 
-procmail: procmail.$(O) $(PM_OBJ) setid
-	$(CC) $(CFLAGS) $@.$(O) $(PM_OBJ) -o $@ $(LDFLAGS)
+procmail$(EXE): procmail.$(O) $(PM_OBJ) setid
+	$(CC) $(CFLAGS) procmail.$(O) $(PM_OBJ) -o $@ $(LDFLAGS)
 	@test -z "$(STRIP)" || ( echo $(STRIP) $@; $(STRIP) $@ )
 
-lockfile: lockfile.$(O) $(LF_OBJ)
-	$(CC) $(CFLAGS) $@.$(O) $(LF_OBJ) -o $@ $(LDFLAGS)
+lockfile$(EXE): lockfile.$(O) $(LF_OBJ)
+	$(CC) $(CFLAGS) lockfile.$(O) $(LF_OBJ) -o $@ $(LDFLAGS)
 	@test -z "$(STRIP)" || ( echo $(STRIP) $@; $(STRIP) $@ )
 
-formail: formail.$(O) $(FM_OBJ)
-	$(CC) $(CFLAGS) $@.$(O) $(FM_OBJ) -o $@ $(LDFLAGS)
+formail$(EXE): formail.$(O) $(FM_OBJ)
+	$(CC) $(CFLAGS) formail.$(O) $(FM_OBJ) -o $@ $(LDFLAGS)
 	@test -z "$(STRIP)" || ( echo $(STRIP) $@; $(STRIP) $@ )
 
 mailstat: ../examples/mailstat
@@ -45,7 +45,7 @@ _autotst: _autotst.$(O) sublib.c sublib.
 ../autoconf.h: autoconf Makefile ../patchlevel.h
 	@echo No this was not make -n >make_n
 	$(SHELL) ./autoconf $(SHELL) "$(RM)" "$(MV)" $(DEVNULL) \
- "$(FGREP)" "$(MAKE)" $(O) "$(LOCKINGTEST)" \
+ "$(FGREP)" "$(MAKE)" $(O) "$(EXE)" "$(LOCKINGTEST)" \
  "$(VISIBLE_BINDIR)" $@
 
 autoconf.h: ../autoconf.h
@@ -185,8 +185,8 @@ clean:
 	$(RM) -r _locktest
 	$(RM) procmail.$(O) $(PM_OBJ) lockfile.$(O) $(LF_OBJ) formail.$O \
  $(FM_OBJ) multigram.$(O) $(MG_OBJ) $(BINSS) multigram ../autoconf.h \
- _autotst* lookfor _locktst* grepfor recommend recommend.$(O) manconf \
- _Makefile lock.log *core* targetdir.h setid setid.$(O) gethome \
+ _autotst* lookfor _locktst* grepfor recommend$(EXE) recommend.$(O) manconf \
+ _Makefile lock.log *core* targetdir.h setid$(EXE) setid.$(O) gethome \
  gethome.$(O) make_n realloc.log
 
 Makefile: ../Makefile Makefile.0
diff -upr procmail-3.22.orig/src/autoconf procmail-3.22/src/autoconf
--- procmail-3.22.orig/src/autoconf	Tue Sep 11 00:55:46 2001
+++ procmail-3.22/src/autoconf	Wed Apr  3 17:41:56 2002
@@ -120,6 +120,7 @@ shift; DEVNULL=$1
 shift; FGREP="$1"
 shift; MAKE="$1"
 shift; O=$1
+shift; EXE=$1
 shift; LOCKINGTEST="$1"
 shift; BINDIR=$1
 shift; ACONF=$1
@@ -674,10 +675,10 @@ else
   kill -15 $$
 fi
 
-$MV _locktst _locktst.$$ 2>$DEVNULL
+$MV _locktst$EXE _locktst.$$ 2>$DEVNULL
 $RM _autotst.$O _autotst.rrr _locktst* 2>$DEVNULL
 echo "" >_locktst.pid
-$MV _autotst _locktst
+$MV _autotst$EXE _locktst$EXE
 
 case "$testdirs" in
   *[a-zA-Z/]*)
@@ -743,7 +744,7 @@ else
      $RM *core*
   fi
 fi
-$RM _autotst.$O _autotst
+$RM _autotst.$O _autotst$EXE
 
 cat >_autotst.c <<HERE
 int main(){volatile int i;return (i=0);}
@@ -882,6 +883,12 @@ else
   echo "#define NO_COMSAT" >>$ACONF
 fi
 
+# Cygwin does not support endprotoent() and endservent()
+case `uname -s` in
+  CYGWIN_NT*) echo "#define NO_COMSAT" >>$ACONF;;
+  *);;
+esac
+
 $RM _autotst.$O
 
 cat >_autotst.c <<HERE
@@ -989,7 +996,7 @@ then
  esac
 fi
 
-$RM _autotst.$O _autotst _autotst.rrr
+$RM _autotst.$O _autotst$EXE _autotst.rrr
 
 cat >_autotst.c <<HERE
 #include "includes.h"
@@ -1073,7 +1080,7 @@ else
   kill -15 $$
 fi
 $MAKE _autotst >_autotst.rrr 2>&1
-$RM _autotst _autotst.$O
+$RM _autotst$EXE _autotst.$O
 
 # The simple ones
 for func in strcspn strpbrk rename pow mkdir fstat initgroups \
@@ -1137,7 +1144,7 @@ HERE
     fi
   fi
   grepfor sys_errlist '#define NOsys_errlist'
-  $RM _autotst _autotst.$O _autotst.rrr
+  $RM _autotst$EXE _autotst.$O _autotst.rrr
 fi
 
  echo 'Testing for brain damage'
@@ -1177,7 +1184,7 @@ HERE
    echo 'Sorry, incompetent bcopy, using substitute instead'
    echo '#define NObcopy' >>$ACONF
  fi
- $RM _autotst.$O _autotst
+ $RM _autotst.$O _autotst$EXE
 fi
 test -f /bin/test && echo "#define GOT_bin_test" >>$ACONF
 
@@ -1349,7 +1356,10 @@ openerr:
 	envs=(char*)((nenv=nenviron)+diff);
 	while(--diff)				       /* put in some colour */
 	   sprintf(*nenviron++=envs,arg,diff),envs+=sizeof arg;
-	*(environ=nenv)="PATH=.";*nenviron=0;diff=argc;	   /* start doubling */
+#ifndef __CYGWIN__
+	*(environ=nenv)="PATH=.";
+#endif /* __CYGWIN__ */
+	*nenviron=0;diff=argc;	   /* start doubling */
       }
      if(MAX_ARGMEM/sizeof arg<=argc)			 /* we are satisfied */
       { einfo=" /* soft limit */";		  /* no reason to hog memory */
@@ -1443,7 +1453,7 @@ chmod 0755 lookfor
 
 if _autotst 2 3 >>$ACONF
    test $? != 0 ||
-    lookfor sendmail || lookfor smail || lookfor mail #|| lookfor rmail
+    lookfor sendmail || lookfor smail || lookfor mail || lookfor ssmtp #|| lookfor rmail
 then
 :
 else

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/