From: Ken Hornstein Date: Fri, 15 Mar 2013 19:57:56 +0000 (-0400) Subject: Mostly complete now, but not yet functional. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/2e08fdfc0ef872c968c2e42b7ee0ede42aee14aa?ds=sidebyside;hp=--cc Mostly complete now, but not yet functional. --- 2e08fdfc0ef872c968c2e42b7ee0ede42aee14aa diff --git a/h/mts.h b/h/mts.h index 1b8f71b5..b425e242 100644 --- 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 ()) diff --git a/h/prototypes.h b/h/prototypes.h index 921021d7..14b12528 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -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 *); diff --git a/m4/locking.m4 b/m4/locking.m4 index e013790a..b70f225f 100644 --- a/m4/locking.m4 +++ b/m4/locking.m4 @@ -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]) diff --git a/sbr/context_read.c b/sbr/context_read.c index 2008c26b..bee5566b 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -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); } diff --git a/sbr/context_save.c b/sbr/context_save.c index 86776c7d..5224af4c 100644 --- a/sbr/context_save.c +++ b/sbr/context_save.c @@ -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) diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 1e49a2a9..8506faf8 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef HAVE_SYS_TIME_H # include @@ -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 diff --git a/sbr/mts.c b/sbr/mts.c index 03578288..70dae024 100644 --- 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 }, diff --git a/sbr/seq_read.c b/sbr/seq_read.c index a807ef7d..2bea5367 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -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); } diff --git a/sbr/seq_save.c b/sbr/seq_save.c index 4055f9d5..837b4bab 100644 --- a/sbr/seq_save.c +++ b/sbr/seq_save.c @@ -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 { /* diff --git a/uip/annosbr.c b/uip/annosbr.c index 5b9fff42..27533f77 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -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; } diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 7771b6b8..09ee2c1f 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -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; } diff --git a/uip/inc.c b/uip/inc.c index 2d791f68..6f7f5946 100644 --- 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); diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 25ac9ab0..5f7e1479 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -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; } diff --git a/uip/msh.c b/uip/msh.c index 4ab73286..2a562f00 100644 --- 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 (); diff --git a/uip/slocal.c b/uip/slocal.c index f570aaaf..ebc2c26b 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -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;