]> diplodocus.org Git - nmh/commitdiff
Mostly complete now, but not yet functional.
authorKen Hornstein <kenh@pobox.com>
Fri, 15 Mar 2013 19:57:56 +0000 (15:57 -0400)
committerKen Hornstein <kenh@pobox.com>
Fri, 15 Mar 2013 19:57:56 +0000 (15:57 -0400)
15 files changed:
h/mts.h
h/prototypes.h
m4/locking.m4
sbr/context_read.c
sbr/context_save.c
sbr/lock_file.c
sbr/mts.c
sbr/seq_read.c
sbr/seq_save.c
uip/annosbr.c
uip/dropsbr.c
uip/inc.c
uip/mhcachesbr.c
uip/msh.c
uip/slocal.c

diff --git a/h/mts.h b/h/mts.h
index 1b8f71b5e983da752acf289ec825bf88132ab110..b425e242b015a4125612a5408e03de25ce2cb05f 100644 (file)
--- a/h/mts.h
+++ b/h/mts.h
@@ -16,6 +16,7 @@ extern char *mmdfldir;
 extern char *mmdflfil;
 extern char *uucpldir;
 extern char *uucplfil;
+extern char *spoollocking;
 
 #define        MAILDIR (mmdfldir && *mmdfldir ? mmdfldir : getenv ("HOME"))
 #define        MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername ())
index 921021d7f3db9d1cb5423ac33fdab7c48015c739..14b1252824fc3bffd8bf670549ca621152737aca 100644 (file)
@@ -88,18 +88,18 @@ char *getfolder(int);
  * file, which will use the locking algorithm configured for the mail
  * spool.
  *
- * All of these functions have a third argument, an integer which
- * indicates the type of lock.  A "0" means a shared (read) lock, and a
- * "1" indicates an exclusive (write) lock.
+ * Files opened for reading are locked with a read lock (if possible by
+ * the underlying lock mechanism), files opened for writing are locked
+ * using an exclusive lock.
  */
-int lkclosedata(int, char*);
-int lkclosespool(int, char*);
-int lkfclosedata(FILE *, char *);
-int lkfclosespool(FILE *, char *);
-FILE *lkfopendata(char *, char *, int);
-int lkopendata(char *, int, mode_t, int);
-FILE *lkfopenspool(char *, char *, int);
-int lkopenspool(char *, int, mode_t, int);
+int lkclosedata(int, const char *);
+int lkclosespool(int, const char *);
+int lkfclosedata(FILE *, const char *);
+int lkfclosespool(FILE *, const char *);
+FILE *lkfopendata(const char *, const char *);
+int lkopendata(const char *, int, mode_t);
+FILE *lkfopenspool(const char *, const char *);
+int lkopenspool(const char *, int, mode_t);
 int m_atoi (char *);
 char *m_backup (char *);
 int m_convert (struct msgs *, char *);
index e013790a5de6e2e0e12794db0f637026b447c3dc..b70f225f3bb0e189f3a166d93e5f900bd22d0dfc 100644 (file)
@@ -33,7 +33,7 @@ AS_CASE([$with_locking],
     [AC_MSG_ERROR([--without-locking not supported])],
   [AC_MSG_ERROR([Unknown locking type $with_locking])])
 
-AC_DEFINE_UNQUOTED([DEFAULT_LOCKING], [$with_locking],
+AC_DEFINE_UNQUOTED([DEFAULT_LOCKING], ["$with_locking"],
   [The default lock type for the mail spool file])
 
 AC_MSG_RESULT([$with_locking])
index 2008c26bcccf2278cc750ae2f82dd05fcc1fa0c9..bee5566b7ee7babc146c400022cde87cffef9b74 100644 (file)
@@ -136,7 +136,7 @@ context_read (void)
     
     ctxpath = getcpy (m_maildir (cp));
 
-    if ((ib = lkfopendata (ctxpath, "r", 0))) {
+    if ((ib = lkfopendata (ctxpath, "r"))) {
        readconfig ((struct node **) 0, ib, cp, 1);
        lkfclosedata (ib, ctxpath);
     }
index 86776c7d4bf53c4bdf18aaf44c31fe68b2723d71..5224af4ce403a7a390c2246fd3d8db82064949e6 100644 (file)
@@ -43,7 +43,7 @@ context_save (void)
     sigaddset (&set, SIGTERM);
     sigprocmask (SIG_BLOCK, &set, &oset);
 
-    if (!(out = lkfopendata (ctxpath, "w", 1)))
+    if (!(out = lkfopendata (ctxpath, "w")))
        adios (ctxpath, "unable to write");
     for (np = m_defs; np; np = np->n_next)
        if (np->n_context)
index 1e49a2a9d17d8873b7abc7cb34b4b7c91691d018..8506faf818c4a05251cf9db72f44eb583abadcb9 100644 (file)
@@ -18,6 +18,7 @@
 #include <h/mh.h>
 #include <h/signals.h>
 #include <h/utils.h>
+#include <h/mts.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -50,6 +51,11 @@ struct lockinfo {
 #endif
 };
 
+/*
+ * Number of tries to retry locking
+ */
+#define LOCK_RETRIES 5
+
 /*
  * Amount of time to wait before
  * updating ctime of lock file.
@@ -79,24 +85,28 @@ enum locktype { FCNTL_LOCKING, FLOCK_LOCKING, LOCKF_LOCKING, DOT_LOCKING };
  */
 static int datalockinit = 0;
 static int spoollockinit = 0;
-enum locktype datalocking, spoollocking;
+static enum locktype datalocktype, spoollocktype;
 
 
 /* top of list containing all open locks */
 static struct lock *l_top = NULL;
 
-static int lkopen(char *, int, mode_t, enum locktype, int);
-static FILE *lkfopen(char *, const char *, mode_t, int);
+static int lkopen(const char *, int, mode_t, enum locktype);
+static int str2accbits(const char *);
 
-static int lkopen_fcntl (char *, int, mode_t, int);
+static int lkopen_fcntl (const char *, int, mode_t);
 #ifdef HAVE_LOCKF
-static int lkopen_lockf (char *, int, mode_t, int);
+static int lkopen_lockf (const char *, int, mode_t);
 #endif /* HAVE_LOCKF */
+#ifdef HAVE_FLOCK
+static int lkopen_flock (const char *, int, mode_t);
+#endif /* HAVE_FLOCK */
 
 static enum locktype init_locktype(const char *);
 
-static int lkopen_dot (char *, int, mode_t);
-static void lockname (char *, struct lockinfo *, int);
+static int lkopen_dot (const char *, int, mode_t);
+static void lkclose_dot (int, const char *);
+static void lockname (const char *, struct lockinfo *, int);
 static void timerON (char *, int);
 static void timerOFF (int);
 static void alrmser (int);
@@ -106,27 +116,175 @@ static int lockit (struct lockinfo *);
 #endif
 
 /*
- * Base function: determine the data type used to lock files and
+ * Base functions: determine the data type used to lock files and
  * call the underlying function.
  */
 
 int
-lkopendata(char *file, int access, mode_t mode, int exclusive)
+lkopendata(const char *file, int access, mode_t mode)
 {
     if (! datalockinit) {
        char *cp = context_find("datalocking");
 
        if (cp) {
-           datalocking = init_locktype(cp);
+           datalocktype = init_locktype(cp);
        } else {
            /* We default to fcntl locking for data files */
-           datalocking = FCNTL_LOCKING;
+           datalocktype = FCNTL_LOCKING;
        }
 
        datalockinit = 1;
     }
 
-    return lkopen(file, access, mode, datalocking, exclusive);
+    return lkopen(file, access, mode, datalocktype);
+}
+
+
+/*
+ * Locking using the spool locking algorithm
+ */
+
+int lkopenspool(const char *file, int access, mode_t mode)
+{
+    if (! spoollockinit) {
+       spoollocktype = init_locktype(spoollocking);
+
+       spoollockinit = 1;
+    }
+
+    return lkopen(file, access, mode, spoollocktype);
+}
+
+
+/*
+ * Versions of lkopen that return a FILE *
+ */
+
+FILE *
+lkfopendata(const char *file, const char *mode)
+{
+    FILE *fp;
+    int oflags = str2accbits(mode);
+    int fd;
+
+    if (oflags == -1) {
+       errno = EINVAL;
+       return NULL;
+    }
+
+    if ((fd = lkopendata(file, oflags, 0666)) == -1)
+       return NULL;
+
+    if ((fp = fdopen (fd, mode)) == NULL) {
+       close (fd);
+       return NULL;
+    }
+
+    return fp;
+}
+
+FILE *
+lkfopenspool(const char *file, const char *mode)
+{
+    FILE *fp;
+    int oflags = str2accbits(mode);
+    int fd;
+
+    if (oflags == -1) {
+       errno = EINVAL;
+       return NULL;
+    }
+
+    if ((fd = lkopenspool(file, oflags, 0666)) == -1)
+       return NULL;
+
+    if ((fp = fdopen (fd, mode)) == NULL) {
+       close (fd);
+       return NULL;
+    }
+
+    return fp;
+}
+
+
+/*
+ * Corresponding close functions.
+ *
+ * A note here: All of the kernel locking functions terminate the lock
+ * when the descriptor is closed, so why write the code to explicitly
+ * unlock the file?  We only need to do this in the dot-locking case.
+ */
+
+int
+lkclosedata(int fd, const char *name)
+{
+    int rc = close(fd);
+
+    if (datalocktype == DOT_LOCKING)
+       lkclose_dot(fd, name);
+
+    return rc;
+}
+
+int
+lkfclosedata(FILE *f, const char *name)
+{
+    int fd = fileno(f);
+    int rc = fclose(f);
+
+    if (datalocktype == DOT_LOCKING)
+       lkclose_dot(fd, name);
+
+    return rc;
+}
+
+int
+lkclosespool(int fd, const char *name)
+{
+    int rc = close(fd);
+
+    if (spoollocktype == DOT_LOCKING)
+       lkclose_dot(fd, name);
+
+    return rc;
+}
+
+int
+lkfclosespool(FILE *f, const char *name)
+{
+    int fd = fileno(f);
+    int rc = fclose(f);
+
+    if (spoollocktype == DOT_LOCKING)
+       lkclose_dot(fd, name);
+
+    return rc;
+}
+
+
+/*
+ * Convert fopen() mode argument to open() bits
+ */
+
+static int
+str2accbits(const char *mode)
+{
+    if (strcmp (mode, "r") == 0)
+       return O_RDONLY;
+    else if (strcmp (mode, "r+") == 0)
+       return O_RDWR;
+    else if (strcmp (mode, "w") == 0)
+       return O_WRONLY | O_CREAT | O_TRUNC;
+    else if (strcmp (mode, "w+") == 0)
+       return O_RDWR | O_CREAT | O_TRUNC;
+    else if (strcmp (mode, "a") == 0)
+       return O_WRONLY | O_CREAT | O_APPEND;
+    else if (strcmp (mode, "a+") == 0)
+       return O_RDWR | O_CREAT | O_APPEND;
+    else {
+       errno = EINVAL;
+       return -1;
+    }
 }
 
 /*
@@ -134,25 +292,24 @@ lkopendata(char *file, int access, mode_t mode, int exclusive)
  */
 
 static int
-lkopen (char *file, int access, mode_t mode, enum locktype ltype,
-       int exclusive)
+lkopen (const char *file, int access, mode_t mode, enum locktype ltype)
 {
     switch (ltype) {
 
     case FCNTL_LOCKING:
-       return lkopen_fcntl(file, access, mode, exclusive);
+       return lkopen_fcntl(file, access, mode);
 
     case DOT_LOCKING:
-       return lkopen_dot(file, access, mode, exclusive);
+       return lkopen_dot(file, access, mode);
 
 #ifdef HAVE_FLOCK
     case FLOCK_LOCKING:
-       return lkopen_flock(file, access, mode, exclusive);
+       return lkopen_flock(file, access, mode);
 #endif /* HAVE_FLOCK */
 
 #ifdef HAVE_LOCKF
     case LOCKF_LOCKING:
-       return lkopen_lockf(file, access, mode, exclusive);
+       return lkopen_lockf(file, access, mode);
 #endif /* HAVE_FLOCK */
 
     default:
@@ -164,43 +321,14 @@ lkopen (char *file, int access, mode_t mode, enum locktype ltype,
 
 
 /*
- * Base routine to close and unlock a file,
- * given a file descriptor.
+ * Routine to clean up the dot locking file
  */
 
-int
-lkclose (int fd, char *file)
+static void
+lkclose_dot (int fd, const char *file)
 {
-#ifdef FCNTL_LOCKING
-    struct flock buf;
-#endif
-
-#ifdef DOT_LOCKING
     struct lockinfo lkinfo;
-#endif
-
-    if (fd == -1)
-       return 0;
-
-#ifdef FCNTL_LOCKING
-    buf.l_type   = F_UNLCK;
-    buf.l_whence = SEEK_SET;
-    buf.l_start  = 0;
-    buf.l_len    = 0;
-    fcntl(fd, F_SETLK, &buf);
-#endif
 
-#ifdef FLOCK_LOCKING
-    flock (fd, LOCK_UN);
-#endif
-
-#ifdef LOCKF_LOCKING
-    /* make sure we unlock the whole thing */
-    lseek (fd, (off_t) 0, SEEK_SET);
-    lockf (fd, F_ULOCK, 0L);
-#endif 
-
-#ifdef DOT_LOCKING
     lockname (file, &lkinfo, 0);       /* get name of lock file */
 #if !defined(HAVE_LIBLOCKFILE)
     unlink (lkinfo.curlock);           /* remove lock file      */
@@ -208,189 +336,138 @@ lkclose (int fd, char *file)
     lockfile_remove(lkinfo.curlock);
 #endif /* HAVE_LIBLOCKFILE */
     timerOFF (fd);                     /* turn off lock timer   */
-#else  /* DOT_LOCKING */
-    NMH_UNUSED (file);
-#endif /* DOT_LOCKING */
-
-    return (close (fd));
 }
 
 
 /*
- * Base routine to open and lock a file,
- * and return a FILE pointer
+ * Open and lock a file, using fcntl locking
  */
 
-FILE *
-lkfopen (char *file, char *mode, int exclusive)
+static int
+lkopen_fcntl(const char *file, int access, mode_t mode)
 {
-    int fd, access;
-    FILE *fp;
+    int fd, i, saved_errno;
+    struct flock flk;
 
-    if (strcmp (mode, "r") == 0)
-       access = O_RDONLY;
-    else if (strcmp (mode, "r+") == 0)
-       access = O_RDWR;
-    else if (strcmp (mode, "w") == 0)
-       access = O_WRONLY | O_CREAT | O_TRUNC;
-    else if (strcmp (mode, "w+") == 0)
-       access = O_RDWR | O_CREAT | O_TRUNC;
-    else if (strcmp (mode, "a") == 0)
-       access = O_WRONLY | O_CREAT | O_APPEND;
-    else if (strcmp (mode, "a+") == 0)
-       access = O_RDWR | O_CREAT | O_APPEND;
-    else {
-       errno = EINVAL;
-       return NULL;
-    }
+    /*
+     * The assumption here is that if you open the file for writing, you
+     * need an exclusive lock.
+     */
 
-    if ((fd = lkopen (file, access, 0666, exclusive)) == -1)
-       return NULL;
+    for (i = 0; i < LOCK_RETRIES; i++) {
+       if ((fd = open(file, access, mode)) == -1)
+           return -1;
 
-    if ((fp = fdopen (fd, mode)) == NULL) {
-       close (fd);
-       return NULL;
+       flk.l_start = 0;
+       flk.l_len = 0;
+       flk.l_type = (access & O_ACCMODE) == O_RDONLY ? F_RDLCK : F_WRLCK;
+       flk.l_whence = SEEK_SET;
+
+       if (fcntl(fd, F_SETLK, &flk) != -1)
+           return fd;
+
+       saved_errno = errno;
+       close(fd);
+       sleep(1);
     }
 
-    return fp;
+    errno = saved_errno;
+    return -1;
 }
 
 
 /*
- * Base routine to close and unlock a file,
- * given a FILE pointer
+ * Open and lock a file, using flock locking
  */
 
-int
-lkfclose (FILE *fp, char *file)
+static int
+lkopen_flock(const char *file, int access, mode_t mode)
 {
-#ifdef FCNTL_LOCKING
-    struct flock buf;
-#endif
-
-#ifdef DOT_LOCKING
-    struct lockinfo lkinfo;
-#endif
+    int fd, i, saved_errno, locktype;
 
-    if (fp == NULL)
-       return 0;
+    /*
+     * The assumption here is that if you open the file for writing, you
+     * need an exclusive lock.
+     */
 
-#ifdef FCNTL_LOCKING
-    buf.l_type   = F_UNLCK;
-    buf.l_whence = SEEK_SET;
-    buf.l_start  = 0;
-    buf.l_len    = 0;
-    fcntl(fileno(fp), F_SETLK, &buf);
-#endif
+    locktype = (((access & O_ACCMODE) == O_RDONLY) ? LOCK_SH : LOCK_EX) |
+                                                       LOCK_NB;
 
-#ifdef FLOCK_LOCKING
-    flock (fileno(fp), LOCK_UN);
-#endif
+    for (i = 0; i < LOCK_RETRIES; i++) {
+       if ((fd = open(file, access, mode)) == -1)
+           return -1;
 
-#ifdef LOCKF_LOCKING
-    /* make sure we unlock the whole thing */
-    fseek (fp, 0L, SEEK_SET);
-    lockf (fileno(fp), F_ULOCK, 0L);
-#endif
+       if (flock(fd, locktype) != -1)
+           return fd;
 
-#ifdef DOT_LOCKING
-    lockname (file, &lkinfo, 0);       /* get name of lock file */
-#if !defined(HAVE_LIBLOCKFILE)
-    unlink (lkinfo.curlock);           /* remove lock file      */
-#else
-    lockfile_remove(lkinfo.curlock);
-#endif /* HAVE_LIBLOCKFILE */
-    timerOFF (fileno(fp));             /* turn off lock timer   */
-#else  /* DOT_LOCKING */
-    NMH_UNUSED (file);
-#endif /* DOT_LOCKING */
+       saved_errno = errno;
+       close(fd);
+       sleep(1);
+    }
 
-    return (fclose (fp));
+    errno = saved_errno;
+    return -1;
 }
 
 
-#ifdef KERNEL_LOCKING
-
 /*
- * open and lock a file, using kernel locking
+ * Open and lock a file, using lockf locking
  */
 
 static int
-lkopen_kernel (char *file, int access, mode_t mode)
+lkopen_lockf(const char *file, int access, mode_t mode)
 {
-    int fd, i, j;
-
-# ifdef FCNTL_LOCKING
-    struct flock buf;
-# endif /* FCNTL_LOCKING */
+    int fd, i, saved_errno, saved_access;
 
-    for (i = 0; i < 5; i++) {
+    /*
+     * Two notes:
+     *
+     * Because lockf locks start from the current offset, mask off O_APPEND
+     * and seek to the end of the file later if it was requested.
+     *
+     * lockf locks require write access to the file, so always add it
+     * even if it wasn't requested.
+     */
 
-# if defined(LOCKF_LOCKING) || defined(FCNTL_LOCKING)
-       /* remember the original mode */
-       j = access;
+    saved_access = access;
 
-       /* make sure we open at the beginning */
-       access &= ~O_APPEND;
+    access &= ~O_APPEND;
 
-       /*
-        * We MUST have write permission or
-        * lockf/fcntl() won't work
-        */
-       if ((access & 03) == O_RDONLY) {
-           access &= ~O_RDONLY;
-           access |= O_RDWR;
-       }
-# endif /* LOCKF_LOCKING || FCNTL_LOCKING */
+    if ((access & O_ACCMODE) == O_RDONLY) {
+       access &= ~O_RDONLY;
+       access |= O_RDWR;
+    }
 
-       if ((fd = open (file, access | O_NDELAY, mode)) == -1)
+    for (i = 0; i < LOCK_RETRIES; i++) {
+       if ((fd = open(file, access, mode)) == -1)
            return -1;
 
-# ifdef FCNTL_LOCKING
-       buf.l_type   = F_WRLCK;
-       buf.l_whence = SEEK_SET;
-       buf.l_start  = 0;
-       buf.l_len    = 0;
-       if (fcntl (fd, F_SETLK, &buf) != -1)
-           return fd;
-# endif
-
-# ifdef FLOCK_LOCKING
-       if (flock (fd, (((access & 03) == O_RDONLY) ? LOCK_SH : LOCK_EX)
-                  | LOCK_NB) != -1)
-           return fd;
-# endif
-
-# ifdef LOCKF_LOCKING
-       if (lockf (fd, F_TLOCK, 0L) != -1) {
-           /* see if we should be at the end */
-           if (j & O_APPEND)
-               lseek (fd, (off_t) 0, SEEK_END);
+       if (lockf(fd, F_TLOCK, 0) != -1) {
+           /*
+            * Seek to end if requested
+            */
+           if (saved_access & O_APPEND) {
+               lseek(fd, 0, SEEK_END);
+           }
            return fd;
        }
-# endif
 
-       j = errno;
-       close (fd);
-       sleep (5);
+       saved_errno = errno;
+       close(fd);
+       sleep(1);
     }
 
-    close (fd);
-    errno = j;
+    errno = saved_errno;
     return -1;
 }
 
-#endif /* KERNEL_LOCKING */
-
-
-#ifdef DOT_LOCKING
 
 /*
  * open and lock a file, using dot locking
  */
 
 static int
-lkopen_dot (char *file, int access, mode_t mode)
+lkopen_dot (const char *file, int access, mode_t mode)
 {
     int fd;
     struct lockinfo lkinfo;
@@ -497,10 +574,11 @@ lockit (struct lockinfo *li)
  */
 
 static void
-lockname (char *file, struct lockinfo *li, int isnewlock)
+lockname (const char *file, struct lockinfo *li, int isnewlock)
 {
     int bplen, tmplen;
-    char *bp, *cp;
+    char *bp;
+    const char *cp;
 
 #if 0
     struct stat st;
@@ -649,7 +727,6 @@ alrmser (int sig)
     alarm (NSECS);
 }
 
-#endif /* DOT_LOCKING */
 
 /*
  * Return a locking algorithm based on the string name
index 03578288d42c9fce3c43180bc795e918fc9bfd49..70dae02485e7268c261b91bf9c5e1ac1de10587b 100644 (file)
--- a/sbr/mts.c
+++ b/sbr/mts.c
@@ -54,6 +54,8 @@ char *uucplfil = "";
 char *mmdlm1 = "\001\001\001\001\n";
 char *mmdlm2 = "\001\001\001\001\n";
 
+char *spoollocking = DEFAULT_LOCKING;
+
 /* Cache the username, fullname, and mailbox of the user */
 static char username[BUFSIZ];
 static char fullname[BUFSIZ];
@@ -102,6 +104,7 @@ static struct bind binds[] = {
     { "systemname", &systemname },
     { "mmdfldir", &mmdfldir },
     { "mmdflfil", &mmdflfil },
+    { "spoollocking", &spoollocking },
     { "uucpldir", &uucpldir },
     { "uucplfil", &uucplfil },
     { "mmdelim1", &mmdlm1 },
index a807ef7d6169b0b000c57535c163590f8e190fd5..2bea5367b8d1a68f9d4ef71910653a4bb5ad448e 100644 (file)
@@ -73,7 +73,7 @@ seq_public (struct msgs *mp)
     /* get filename of sequence file */
     snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);
 
-    if ((fp = lkfopen (seqfile, "r")) == NULL)
+    if ((fp = lkfopendata (seqfile, "r")) == NULL)
        return;
 
     /* Use m_getfld to scan sequence file */
@@ -110,7 +110,7 @@ seq_public (struct msgs *mp)
     }
     m_getfld_state_destroy (&gstate);
 
-    lkfclose (fp, seqfile);
+    lkfclosedata (fp, seqfile);
 }
 
 
index 4055f9d5f1cc9c429442d3c3957bce91946b97e3..837b4bab4147c0ebd88fe0e4a291df90b328af0d 100644 (file)
@@ -74,9 +74,9 @@ priv:
                 * If that fails (probably because folder is
                 * readonly), then make sequence private.
                 */
-               if ((fp = lkfopen (seqfile, "w")) == NULL
+               if ((fp = lkfopendata (seqfile, "w")) == NULL
                        && (unlink (seqfile) == -1 ||
-                           (fp = lkfopen (seqfile, "w")) == NULL)) {
+                           (fp = lkfopendata (seqfile, "w")) == NULL)) {
                    admonish (attr, "unable to write");
                    goto priv;
                }
@@ -94,7 +94,7 @@ priv:
     }
 
     if (fp) {
-       lkfclose (fp, seqfile);
+       lkfclosedata (fp, seqfile);
        sigprocmask (SIG_SETMASK, &oset, &set);  /* reset signal mask */
     } else {
        /*
index 5b9fff42dc45c58b4b8dc704b7f42558308122cf..27533f7788ef3aaa7734c1b644bd65a141dff63e 100644 (file)
@@ -35,7 +35,7 @@ annotate (char *file, char *comp, char *text, int inplace, int datesw, int delet
     struct stat                s;
 
     /* open and lock the file to be annotated */
-    if ((fd = lkopen (file, O_RDWR, 0)) == NOTOK) {
+    if ((fd = lkopendata (file, O_RDWR, 0)) == NOTOK) {
        switch (errno) {
            case ENOENT:
                break;
@@ -60,7 +60,7 @@ annotate (char *file, char *comp, char *text, int inplace, int datesw, int delet
     if (preserve_actime_and_modtime && utime(file, &b) == -1)
        advise("can't set access and modification times for %s", file);
 
-    lkclose (fd, file);
+    lkclosedata (fd, file);
     return i;
 }
 
index 7771b6b81d51c2e0b76420b77999be5cbc698300..09ee2c1f6a698de052b8e738260888ed6e8af666 100644 (file)
@@ -48,7 +48,8 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode)
 
     /* attempt to open and lock file */
     for (count = 4; count > 0; count--) {
-       if ((fd = lkopen (file, O_RDWR | O_CREAT | O_NONBLOCK, mode)) == NOTOK) {
+       if ((fd = lkopenspool (file, O_RDWR | O_CREAT |
+                              O_NONBLOCK, mode)) == NOTOK) {
            switch (errno) {
 #if defined(FCNTL_LOCKING) || defined(LOCKF_LOCKING)
                case EACCES:
@@ -463,7 +464,7 @@ mbx_size (int md, off_t start, off_t stop)
 int
 mbx_close (char *mailbox, int md)
 {
-    if (lkclose (md, mailbox) == 0)
+    if (lkclosespool (md, mailbox) == 0)
         return OK;
     return NOTOK;
 }
index 2d791f68383949d657f65a1fc91abbbcc75962e2..6f7f5946716bcc72023f7cf488dad192eced16bd 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -531,7 +531,7 @@ go_to_it:
            }
 
             GETGROUPPRIVS();       /* Reset gid to lock mail file */
-            in = lkfopen (newmail, "r");
+            in = lkfopenspool (newmail, "r");
             DROPGROUPPRIVS();
             if (in == NULL)
                adios (NULL, "unable to lock and fopen %s", newmail);
@@ -875,7 +875,7 @@ go_to_it:
     if (incerr < 0) {          /* error */
        if (locked) {
             GETGROUPPRIVS();      /* Be sure we can unlock mail file */
-            (void) lkfclose (in, newmail); in = NULL;
+            (void) lkfclosespool (in, newmail); in = NULL;
             DROPGROUPPRIVS();    /* And then return us to normal privileges */
        } else {
            fclose (in); in = NULL;
@@ -932,7 +932,7 @@ go_to_it:
     if (inc_type == INC_FILE && Maildir == NULL) {
        if (locked) {
            GETGROUPPRIVS();        /* Be sure we can unlock mail file */
-           (void) lkfclose (in, newmail); in = NULL;
+           (void) lkfclosespool (in, newmail); in = NULL;
            DROPGROUPPRIVS();       /* And then return us to normal privileges */
        } else {
            fclose (in); in = NULL;
@@ -955,7 +955,7 @@ inc_done (int status)
     if (locked)
     {
         GETGROUPPRIVS();
-        lkfclose(in, newmail);
+        lkfclosespool(in, newmail);
         DROPGROUPPRIVS();
     }
     exit (status);
index 25ac9ab0b7a430654b9747e870dcf8752b9c08f7..5f7e147919aef84776ec1092d0e994c3ba1bc1be 100644 (file)
@@ -344,19 +344,19 @@ use_raw:
 
     make_intermediates (mapfile);
     mask = umask (writing == 2 ? 0077 : 0);
-    if (!(fp = lkfopen (mapfile, "a")) && errno == ENOENT) {
+    if (!(fp = lkfopendata (mapfile, "a")) && errno == ENOENT) {
        int fd;
 
        if ((fd = creat (mapfile, 0666)) != NOTOK) {
            close (fd);
-           fp = lkfopen (mapfile, "a");
+           fp = lkfopendata (mapfile, "a");
        }
     }
     umask (mask);
     if (!fp)
        return NOTOK;
     fprintf (fp, "%s: %s\n", mapname, id);
-    lkfclose (fp, mapfile);
+    lkfclosedata (fp, mapfile);
 
 done_map:
     if (*mapname == '/')
@@ -378,7 +378,7 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
     FILE *fp;
     m_getfld_state_t gstate = 0;
 
-    if (!(fp = lkfopen (mapfile, "r")))
+    if (!(fp = lkfopendata (mapfile, "r")))
        return NOTOK;
 
     for (;;) {
@@ -409,7 +409,7 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
                result = strcmp (id, dp);
                free (dp);
                if (result == 0) {
-                   lkfclose (fp, mapfile);
+                   lkfclosedata (fp, mapfile);
                    return OK;
                }
                continue;
@@ -423,6 +423,6 @@ find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen)
     }
     m_getfld_state_destroy (&gstate);
 
-    lkfclose (fp, mapfile);
+    lkfclosedata (fp, mapfile);
     return NOTOK;
 }
index 4ab73286825fa15e15dd331176ec62b24affa938..2a562f007a0e359a461629496c1489252aa57dfd 100644 (file)
--- a/uip/msh.c
+++ b/uip/msh.c
@@ -1097,7 +1097,7 @@ quit (void)
     if (vmh) 
        ttyNaux (NULLCMD, "FAST");
     cp = NULL;
-    if ((dp = lkfopen (mp->foldpath, "r")) == NULL) {
+    if ((dp = lkfopendata (mp->foldpath, "r")) == NULL) {
        advise (mp->foldpath, "unable to lock");
        if (vmh) {
            ttyR (NULLCMD);
@@ -1161,7 +1161,7 @@ quit (void)
 release: ;
     if (cp)
        free (cp);
-    lkfclose (dp, mp->foldpath);
+    lkfclosedata (dp, mp->foldpath);
     if (vmh) {
        ttyR (NULLCMD);
        pFIN ();
index f570aaaff2a0082373283e8c4b84eeb76f16f132..ebc2c26b9854ca3abf2e36b1eafce51abb8ef2d2 100644 (file)
@@ -1453,7 +1453,7 @@ suppress_duplicates (int fd, char *file)
                 * This will fail if your Maildelivery file doesn't
                 * exist.
                 */
-               if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) {
+               if ((lockfd = lkopendata(file, O_RDWR, 0)) == -1) {
                    advise (file, "unable to perform file locking on");
                    free (cp);
                    fclose (in);
@@ -1474,7 +1474,7 @@ suppress_duplicates (int fd, char *file)
                }
 
                dbm_close (db);
-               lkclose(lockfd, file);
+               lkclosedata(lockfd, file);
                free (cp);
                fclose (in);
                return result;