[gnu.emacs.bug] MMDF patches for etc/movemail.c

lmjm%doc.imperial.ac.uk@NSFNET-RELAY.AC.UK (05/14/89)

Here are some patches for the 18.51 version of movemail.c to allow it
to use MMDF's locking routines.  It needs to be compiled with '-DMMDF'
and needs to be linked with the main mmdf library (normally mmdf/lib/libmmdf.a)

Sorry that the only machine with gnuemacs and MMDF is only 18.51 so
I've not tried these patches on anything newer.

*** movemail.c.orig	Sun May 14 12:04:54 1989
--- movemail.c	Sun May 14 13:24:49 1989
***************
*** 35,40 ****
--- 35,43 ----
   *	get_errmsg - return pointer to system error message
   *
   */
+ /* Modified May 1989 to support MMDF locking by L.McLoughlin,
+  * Department of Computing, Imperial College, London, UK
+  */
  
  #include <sys/types.h>
  #include <sys/stat.h>
***************
*** 51,56 ****
--- 54,64 ----
  #include <sys/locking.h>
  #endif
  
+ #ifdef MMDF
+ extern int lk_open(), lk_close();
+ #undef USE_MAIL_FLOCK
+ #endif
+ 
  /* Cancel substitutions made by config.h for Emacs.  */
  #undef open
  #undef read
***************
*** 69,75 ****
    char buf[1024];
    int nread;
  
! #ifndef MAIL_USE_FLOCK
    struct stat st;
    long now;
    int tem;
--- 77,83 ----
    char buf[1024];
    int nread;
  
! #if !defined(MAIL_USE_FLOCK) && !defined(MMDF)
    struct stat st;
    long now;
    int tem;
***************
*** 84,89 ****
--- 92,101 ----
    inname = argv[1];
    outname = argv[2];
  
+ #ifdef MMDF
+   mmdf_init( argv[ 0 ] );
+ #endif
+ 
  #ifdef MAIL_USE_POP
    if (!bcmp (inname, "po:", 3))
      {
***************
*** 97,103 ****
    setuid (getuid());
  #endif /* MAIL_USE_POP */
  
! #ifndef MAIL_USE_FLOCK
    /* Use a lock file named /usr/spool/mail/$USER.lock:
       If it exists, the mail file is locked.  */
    lockname = concat (inname, ".lock", "");
--- 109,115 ----
    setuid (getuid());
  #endif /* MAIL_USE_POP */
  
! #if !defined(MAIL_USE_FLOCK) && !defined(MMDF)
    /* Use a lock file named /usr/spool/mail/$USER.lock:
       If it exists, the mail file is locked.  */
    lockname = concat (inname, ".lock", "");
***************
*** 138,144 ****
--- 150,160 ----
  #ifdef MAIL_USE_FLOCK
    indesc = open (inname, O_RDWR);
  #else /* if not MAIL_USE_FLOCK */
+ # ifdef MMDF
+   indesc = lk_open( inname, O_RDONLY, (char *)0, (char *)0, 10 );
+ # else
    indesc = open (inname, O_RDONLY);
+ # endif
  #endif /* not MAIL_USE_FLOCK */
    if (indesc < 0)
      pfatal_with_name (inname);
***************
*** 167,173 ****
  	{
  	  int saved_errno = errno;
  	  (void) unlink (outname);
! #ifndef MAIL_USE_FLOCK
  	  (void) unlink (lockname);
  #endif /* not MAIL_USE_FLOCK */ 
  	  errno = saved_errno;
--- 183,189 ----
  	{
  	  int saved_errno = errno;
  	  (void) unlink (outname);
! #if !defined(MAIL_USE_FLOCK) && !defined(MMDF)
  	  (void) unlink (lockname);
  #endif /* not MAIL_USE_FLOCK */ 
  	  errno = saved_errno;
***************
*** 185,191 ****
--- 201,211 ----
    (void) ftruncate (indesc, 0L);
  #endif /* STRIDE or XENIX */
  #endif /* MAIL_USE_FLOCK */
+ #ifdef MMDF
+   (void) lk_close( indesc, (char *)0, (char *)0, (char *)0 );
+ #else
    close (indesc);
+ #endif
    close (outdesc);
  #ifndef MAIL_USE_FLOCK
    /* Delete the input file; if we can't, at least get rid of its contents.  */
***************
*** 192,198 ****
--- 212,220 ----
    if (unlink (inname) < 0)
      if (errno != ENOENT)
        creat (inname, 0666);
+ #ifndef MMDF
    unlink (lockname);
+ #endif
  #endif /* not MAIL_USE_FLOCK */
    exit (0);
  }

--
Lee McLoughlin			01 589 5111 X 5028
Department of Computing,Imperial College,180 Queens Gate,London SW7 2BZ, UK
Janet: lmjm@uk.ac.ic.doc	Uucp:  lmjm@icdoc.UUCP (or ..!ukc!icdoc!lmjm)
DARPA: lmjm@doc.ic.ac.uk (or lmjm%uk.ac.ic.doc@nsfnet-relay.ac.uk)