🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #876

SVR4-conforming mailbox locking in etc/movemail

#876
From: Marc Boucher
Date: Fri, 20 Nov 1992 11:05
138 lines
3441 bytes
Hello,

I have made movemail conformant to SVR4 mailbox locking conventions.
Here are the diffs..

-- 
^@-------~~--**----/ --- - Marc Boucher
marc@CAM.ORG \----?	":
/-----_--  -    ----_|| +1 514 466 8932 - &-

--- 1.1	1992/08/17 11:34:13
+++ Makefile	1992/11/20 20:47:30
@@ -1,4 +1,6 @@
-CFLAGS= -g
+CFLAGS= -O
+# For SVR4.  Needed for movemail
+  LOADLIBES= -lmail
 # For Xenix.  Needed for movemail
 #  LOADLIBES= -lx
 # For Mips.  Needed for who knows what.
--- 1.1	1992/11/20 20:27:56
+++ movemail.c	1992/11/20 21:00:17
@@ -31,6 +31,13 @@
    a setuid or setgid program.  */
 
 /*
+ * SVR4 support by Marc Boucher <marc@CAM.ORG>:
+ *   compile with __svr4__ defined (implicit if gcc used)
+ *   link with -lmail
+ *   install setgid "mail".
+ */
+
+/*
  * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
  *
  * Added POP (Post Office Protocol) service.  When compiled -DPOP
@@ -66,6 +73,12 @@
 #endif
 #endif /* USG */
 
+#ifdef __svr4__
+#undef MAIL_USE_FLOCK
+#include <maillock.h>
+#include <string.h>
+#endif
+
 #ifdef XENIX
 #include <sys/locking.h>
 #endif
@@ -83,8 +96,10 @@
 char *concat ();
 extern int errno;
 
+#ifndef __svr4__
 /* Nonzero means this is name of a lock file to delete on fatal error.  */
 char *delete_lockname;
+#endif
 
 main (argc, argv)
      int argc;
@@ -95,7 +110,7 @@
   char buf[1024];
   int nread;
 
-#ifndef MAIL_USE_FLOCK
+#if !defined(MAIL_USE_FLOCK) && !defined(__svr4__)
   struct stat st;
   long now;
   int tem;
@@ -102,9 +117,7 @@
   char *lockname, *p;
   char tempname[40];
   int desc;
-#endif /* not MAIL_USE_FLOCK */
-
-  delete_lockname = 0;
+#endif /* not MAIL_USE_FLOCK and not __svr4__ */
 
   if (argc < 3)
     fatal ("two arguments required");
@@ -153,6 +166,15 @@
     pfatal_with_name (inname);
 
 #ifndef MAIL_USE_MMDF
+#ifdef __svr4__
+  {
+    char *p;
+
+    p = strrchr(inname, '/') ? strrchr(inname, '/') + 1: inname;
+    if(maillock(p, 5) != L_SUCCESS)
+      fatal ("maillock(%s, 5) failed", p);
+  }
+#else
 #ifndef MAIL_USE_FLOCK
   /* Use a lock file named /usr/spool/mail/$USER.lock:
      If it exists, the mail file is locked.  */
@@ -213,6 +235,7 @@
 
   delete_lockname = lockname;
 #endif /* not MAIL_USE_FLOCK */
+#endif /* __svr4__ */
 
 #ifdef MAIL_USE_FLOCK
   indesc = open (inname, O_RDWR);
@@ -258,7 +281,7 @@
 	break;
     }
 
-#ifdef BSD
+#if defined(BSD) || defined(__svr4__)
   if (fsync (outdesc) < 0)
     pfatal_and_delete (outname);
 #endif
@@ -288,7 +311,11 @@
     if (errno != ENOENT)
       creat (inname, 0666);
 #ifndef MAIL_USE_MMDF
+#ifdef __svr4__
+  mailunlock();
+#else
   unlink (lockname);
+#endif
 #endif /* not MAIL_USE_MMDF */
 #endif /* not MAIL_USE_FLOCK */
   exit (0);
@@ -299,8 +326,12 @@
 fatal (s1, s2)
      char *s1, *s2;
 {
+#ifdef __svr4__
+  mailunlock();
+#else
   if (delete_lockname)
     unlink (delete_lockname);
+#endif
   error (s1, s2);
   exit (1);
 }
Technical Details
Message-ID: <199211202105.AA05422@Altitude.CAM.ORG>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cam.org!marc

Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cam.org!marc
From: marc@cam.org (Marc Boucher)
Subject: SVR4-conforming mailbox locking in etc/movemail
Message-ID: <199211202105.AA05422@Altitude.CAM.ORG>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 20 Nov 1992 11:05:18 GMT
Approved: bug-gnu-emacs@prep.ai.mit.edu
Lines: 139