clean up file locking (create a lockfile() routine in conf.c)
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 18 Mar 1993 01:55:32 +0000 (17:55 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 18 Mar 1993 01:55:32 +0000 (17:55 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 6.28
SCCS-vsn: usr.sbin/sendmail/src/main.c 6.38
SCCS-vsn: usr.sbin/sendmail/src/envelope.c 6.22
SCCS-vsn: usr.sbin/sendmail/src/conf.h 6.11
SCCS-vsn: usr.sbin/sendmail/src/util.c 6.13
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 6.46
SCCS-vsn: usr.sbin/sendmail/src/queue.c 6.27
SCCS-vsn: usr.sbin/sendmail/src/conf.c 6.36
SCCS-vsn: usr.sbin/sendmail/src/alias.c 6.26
SCCS-vsn: usr.sbin/sendmail/src/udb.c 6.13
SCCS-vsn: usr.sbin/sendmail/src/map.c 6.6

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/conf.c
usr/src/usr.sbin/sendmail/src/conf.h
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/envelope.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/map.c
usr/src/usr.sbin/sendmail/src/queue.c
usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/udb.c
usr/src/usr.sbin/sendmail/src/util.c

index d2c247b..1746d27 100644 (file)
@@ -10,7 +10,6 @@
 # include <sys/stat.h>
 # include <sys/file.h>
 # include <signal.h>
 # include <sys/stat.h>
 # include <sys/file.h>
 # include <signal.h>
-# include <fcntl.h>
 # include <pwd.h>
 
 # ifdef DBM
 # include <pwd.h>
 
 # ifdef DBM
@@ -28,15 +27,15 @@ ERROR: DBM is no longer supported -- use NDBM instead.
 #ifndef lint
 #ifdef NEWDB
 #ifdef NDBM
 #ifndef lint
 #ifdef NEWDB
 #ifdef NDBM
-static char sccsid[] = "@(#)alias.c    6.25 (Berkeley) %G% (with NEWDB and NDBM)";
+static char sccsid[] = "@(#)alias.c    6.26 (Berkeley) %G% (with NEWDB and NDBM)";
 #else
 #else
-static char sccsid[] = "@(#)alias.c    6.25 (Berkeley) %G% (with NEWDB)";
+static char sccsid[] = "@(#)alias.c    6.26 (Berkeley) %G% (with NEWDB)";
 #endif
 #else
 #ifdef NDBM
 #endif
 #else
 #ifdef NDBM
-static char sccsid[] = "@(#)alias.c    6.25 (Berkeley) %G% (with NDBM)";
+static char sccsid[] = "@(#)alias.c    6.26 (Berkeley) %G% (with NDBM)";
 #else
 #else
-static char sccsid[] = "@(#)alias.c    6.25 (Berkeley) %G% (without NEWDB or NDBM)";
+static char sccsid[] = "@(#)alias.c    6.26 (Berkeley) %G% (without NEWDB or NDBM)";
 #endif
 #endif
 #endif /* not lint */
 #endif
 #endif
 #endif /* not lint */
@@ -501,11 +500,9 @@ readaliases(aliasfile, init, e)
 # endif
 # ifdef NDBM
        DBM *dbmp;
 # endif
 # ifdef NDBM
        DBM *dbmp;
-# endif
-# ifdef LOCKF
-       struct flock fld;
 # endif
        char line[BUFSIZ];
 # endif
        char line[BUFSIZ];
+       extern bool lockfile();
 
        if ((af = fopen(aliasfile, "r+")) == NULL)
        {
 
        if ((af = fopen(aliasfile, "r+")) == NULL)
        {
@@ -520,24 +517,14 @@ readaliases(aliasfile, init, e)
 
 # if defined(NDBM) || defined(NEWDB)
        /* see if someone else is rebuilding the alias file already */
 
 # if defined(NDBM) || defined(NEWDB)
        /* see if someone else is rebuilding the alias file already */
-# ifdef LOCKF
-       fld.l_type = F_WRLCK;
-       fld.l_whence = fld.l_start = fld.l_len = 0;
-       if (fcntl(fileno(af), F_SETLK, &fld) < 0)
-# else
-       if (flock(fileno(af), LOCK_EX | LOCK_NB) < 0 && errno == EWOULDBLOCK)
-# endif
+       if (!lockfile(fileno(af), aliasfile, LOCK_EX|LOCK_NB))
        {
                /* yes, they are -- wait until done and then return */
                message("Alias file is already being rebuilt");
                if (OpMode != MD_INITALIAS)
                {
                        /* wait for other rebuild to complete */
        {
                /* yes, they are -- wait until done and then return */
                message("Alias file is already being rebuilt");
                if (OpMode != MD_INITALIAS)
                {
                        /* wait for other rebuild to complete */
-# ifdef LOCKF
-                       (void) fcntl(fileno(af), F_SETLKW, &fld);
-# else
-                       (void) flock(fileno(af), LOCK_EX);
-# endif
+                       (void) lockfile(fileno(af), aliasfile, LOCK_EX);
                }
                (void) fclose(af);
                errno = 0;
                }
                (void) fclose(af);
                errno = 0;
index a35b187..aaf8293 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)conf.c     6.35 (Berkeley) %G%";
+static char sccsid[] = "@(#)conf.c     6.36 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <sys/ioctl.h>
 #endif /* not lint */
 
 # include <sys/ioctl.h>
@@ -584,7 +584,6 @@ rlsesigs()
 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT)
 
 #include <nlist.h>
 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT)
 
 #include <nlist.h>
-#include <fcntl.h>
 
 #ifndef LA_AVENRUN
 #define LA_AVENRUN     "_avenrun"
 
 #ifndef LA_AVENRUN
 #define LA_AVENRUN     "_avenrun"
@@ -793,6 +792,12 @@ refuseconnections()
 **             display the title.
 */
 
 **             display the title.
 */
 
+#ifdef SETPROCTITLE
+# ifdef __hpux
+#  include <sys/pstat.h>
+# endif
+#endif
+
 char   ProcTitleBuf[MAXLINE];
 
 /*VARARGS1*/
 char   ProcTitleBuf[MAXLINE];
 
 /*VARARGS1*/
@@ -808,6 +813,9 @@ setproctitle(fmt, va_alist)
        register char *p;
        register int i;
        VA_LOCAL_DECL
        register char *p;
        register int i;
        VA_LOCAL_DECL
+#  ifdef __hpux
+       union pstun pst;
+#  endif
        extern char **Argv;
        extern char *LastArgv;
 
        extern char **Argv;
        extern char *LastArgv;
 
@@ -840,6 +848,7 @@ setproctitle(fmt, va_alist)
        p = &Argv[0][i];
        while (p < LastArgv)
                *p++ = ' ';
        p = &Argv[0][i];
        while (p < LastArgv)
                *p++ = ' ';
+#  endif
 # endif /* SETPROCTITLE */
 }
 \f/*
 # endif /* SETPROCTITLE */
 }
 \f/*
@@ -936,7 +945,11 @@ unsetenv(name)
 int
 getdtablesize()
 {
 int
 getdtablesize()
 {
+# ifdef _SC_OPEN_MAX
+       return sysconf(_SC_OPEN_MAX);
+# else
        return NOFILE;
        return NOFILE;
+# endif
 }
 
 #endif
 }
 
 #endif
@@ -1236,3 +1249,54 @@ transienterror(err)
        /* nope, must be permanent */
        return FALSE;
 }
        /* nope, must be permanent */
        return FALSE;
 }
+\f/*
+**  LOCKFILE -- lock a file using flock or (shudder) lockf
+**
+**     Parameters:
+**             fd -- the file descriptor of the file.
+**             filename -- the file name (for error messages).
+**             type -- type of the lock.  Bits can be:
+**                     LOCK_EX -- exclusive lock.
+**                     LOCK_NB -- non-blocking.
+**
+**     Returns:
+**             TRUE if the lock was acquired.
+**             FALSE otherwise.
+*/
+
+bool
+lockfile(fd, filename, type)
+       int fd;
+       char *filename;
+       int type;
+{
+# ifdef LOCKF
+       int action;
+       struct flock lfd;
+
+       if (bitset(LOCK_EX, type)
+               lfd.l_type = F_WRLCK;
+       else
+               lfd.l_type = F_RDLCK;
+
+       if (bitset(LOCK_NB, type))
+               action = F_SETLK;
+       else
+               action = F_SETLKW;
+
+       lfd.l_whence = lfd.l_start = lfd.l_len = 0;
+
+       if (fcntl(fd, action, &lfd) >= 0)
+               return TRUE;
+
+       if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN))
+               syserr("cannot lockf(%s)", filename);
+# else
+       if (flock(fd, type) >= 0)
+               return TRUE;
+
+       if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK)
+               syserr("cannot flock(%s)", filename);
+# endif
+       return FALSE;
+}
index 1c38ef5..bb1137c 100644 (file)
@@ -5,7 +5,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)conf.h      6.10 (Berkeley) %G%
+ *     @(#)conf.h      6.11 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -13,6 +13,7 @@
 */
 
 # include <sys/param.h>
 */
 
 # include <sys/param.h>
+# include <fcntl.h>
 
 /*
 **  Table sizes, etc....
 
 /*
 **  Table sizes, etc....
@@ -150,3 +151,9 @@ struct utsname
 #ifndef STDERR_FILENO
 #define STDERR_FILENO  2
 #endif
 #ifndef STDERR_FILENO
 #define STDERR_FILENO  2
 #endif
+
+#ifdef LOCKF
+#define LOCK_SH                0x01    /* shared lock */
+#define LOCK_EX                0x02    /* exclusive lock */
+#define LOCK_NB                0x04    /* non-blocking lock */
+#endif
index cd48f8c..4e471e8 100644 (file)
@@ -7,14 +7,13 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  6.45 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  6.46 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #include <signal.h>
 #include <sys/stat.h>
 #include <netdb.h>
 #endif /* not lint */
 
 #include "sendmail.h"
 #include <signal.h>
 #include <sys/stat.h>
 #include <netdb.h>
-#include <fcntl.h>
 #include <errno.h>
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
 #include <errno.h>
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
@@ -347,7 +346,6 @@ deliver(e, firstto)
        if (tobuf[0] == '\0')
        {
                define('g', (char *) NULL, e);
        if (tobuf[0] == '\0')
        {
                define('g', (char *) NULL, e);
-               define('<', (char *) NULL, e);
                return (0);
        }
 
                return (0);
        }
 
@@ -510,7 +508,6 @@ deliver(e, firstto)
 
        errno = 0;
        define('g', (char *) NULL, e);
 
        errno = 0;
        define('g', (char *) NULL, e);
-       define('<', (char *) NULL, e);
        return (rcode);
 }
 \f/*
        return (rcode);
 }
 \f/*
@@ -1495,9 +1492,6 @@ sendall(e, mode)
        char *owner;
        int otherowners;
        ENVELOPE *splitenv = NULL;
        char *owner;
        int otherowners;
        ENVELOPE *splitenv = NULL;
-# ifdef LOCKF
-       struct flock lfd;
-# endif
 
        /* determine actual delivery mode */
        if (mode == SM_DEFAULT)
 
        /* determine actual delivery mode */
        if (mode == SM_DEFAULT)
@@ -1725,6 +1719,9 @@ sendenvelope(e, mode)
        bool oldverbose;
        int pid;
        register ADDRESS *q;
        bool oldverbose;
        int pid;
        register ADDRESS *q;
+#ifdef LOCKF
+       struct flock lfd;
+#endif
 
        oldverbose = Verbose;
        switch (mode)
 
        oldverbose = Verbose;
        switch (mode)
index 05ca2b5..38056c3 100644 (file)
@@ -7,14 +7,13 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)envelope.c 6.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)envelope.c 6.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <pwd.h>
 #endif /* not lint */
 
 #include "sendmail.h"
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <pwd.h>
-#include <fcntl.h>
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
 
 /*
 **  NEWENVELOPE -- allocate a new envelope
index 642bb9d..7fb3989 100644 (file)
@@ -13,16 +13,15 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     6.37 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     6.38 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 
 #endif /* not lint */
 
 #define        _DEFINE
 
-#include <fcntl.h>
+#include "sendmail.h"
 #include <sys/stat.h>
 #include <signal.h>
 #include <sgtty.h>
 #include <sys/stat.h>
 #include <signal.h>
 #include <sgtty.h>
-#include "sendmail.h"
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
 #include <resolv.h>
 #ifdef NAMED_BIND
 #include <arpa/nameser.h>
 #include <resolv.h>
@@ -878,8 +877,10 @@ main(argc, argv, envp)
        **  Do basic system initialization and set the sender
        */
 
        **  Do basic system initialization and set the sender
        */
 
+# ifndef SYSTEM5
        /* make sendmail immune from process group signals */
        (void) setpgrp(0, getpid());
        /* make sendmail immune from process group signals */
        (void) setpgrp(0, getpid());
+# endif
 
        initsys(CurEnv);
        setsender(from, CurEnv, NULL);
 
        initsys(CurEnv);
        setsender(from, CurEnv, NULL);
index f22cfc0..3b92e5c 100644 (file)
@@ -7,11 +7,10 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)map.c      6.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)map.c      6.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
-#include <fcntl.h>
 
 #ifdef DBM_MAP
 #include <ndbm.h>
 
 #ifdef DBM_MAP
 #include <ndbm.h>
index ec70b8d..a24b290 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef QUEUE
 
 #ifndef lint
 #ifdef QUEUE
-static char sccsid[] = "@(#)queue.c    6.26 (Berkeley) %G% (with queueing)";
+static char sccsid[] = "@(#)queue.c    6.27 (Berkeley) %G% (with queueing)";
 #else
 #else
-static char sccsid[] = "@(#)queue.c    6.26 (Berkeley) %G% (without queueing)";
+static char sccsid[] = "@(#)queue.c    6.27 (Berkeley) %G% (without queueing)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -22,7 +22,6 @@ static char sccsid[] = "@(#)queue.c   6.26 (Berkeley) %G% (without queueing)";
 # include <signal.h>
 # include <errno.h>
 # include <pwd.h>
 # include <signal.h>
 # include <errno.h>
 # include <pwd.h>
-# include <fcntl.h>
 # ifndef MAXNAMLEN
 # include <dirent.h>
 # endif
 # ifndef MAXNAMLEN
 # include <dirent.h>
 # endif
@@ -109,9 +108,7 @@ queueup(e, queueall, announce)
                /* get a locked tf file */
                for (i = 100; --i >= 0; )
                {
                /* get a locked tf file */
                for (i = 100; --i >= 0; )
                {
-# ifdef LOCKF
-                       struct flock lfd;
-# endif
+                       extern bool lockfile();
 
                        fd = open(tf, O_CREAT|O_WRONLY|O_EXCL, FileMode);
                        if (fd < 0)
 
                        fd = open(tf, O_CREAT|O_WRONLY|O_EXCL, FileMode);
                        if (fd < 0)
@@ -121,19 +118,10 @@ queueup(e, queueall, announce)
                                syserr("queueup: cannot create temp file %s", tf);
                                return;
                        }
                                syserr("queueup: cannot create temp file %s", tf);
                                return;
                        }
-# ifdef LOCKF
-                       lfd.l_type = F_WRLCK;
-                       lfd.l_whence = lfd.l_start = lfd.l_len = 0;
-                       if (fcntl(fd, F_SETLK, &lfd) >= 0)
-                               break;
-                       if (errno != EACCES && errno != EAGAIN)
-                               syserr("cannot lockf(%s)", tf);
-# else
-                       if (flock(fd, LOCK_EX|LOCK_NB) >= 0)
+
+                       if (lockfile(fd, tf, LOCK_EX|LOCK_NB))
                                break;
                                break;
-                       if (errno != EWOULDBLOCK)
-                               syserr("cannot flock(%s)", tf);
-# endif
+
                        close(fd);
                }
 
                        close(fd);
                }
 
@@ -866,9 +854,7 @@ readqf(e)
        extern char *fgetfolded();
        extern long atol();
        extern ADDRESS *setctluser();
        extern char *fgetfolded();
        extern long atol();
        extern ADDRESS *setctluser();
-# ifdef LOCKF
-       struct flock lfd;
-# endif
+       extern bool lockfile();
        extern ADDRESS *sendto();
 
        /*
        extern ADDRESS *sendto();
 
        /*
@@ -908,28 +894,15 @@ readqf(e)
                return FALSE;
        }
 
                return FALSE;
        }
 
-# ifdef LOCKF
-       lfd.l_type = F_WRLCK;
-       lfd.l_whence = lfd.l_start = lfd.l_len = 0;
-       if (fcntl(fileno(qfp), F_SETLK, &lfd) < 0)
-# else
-       if (flock(fileno(qfp), LOCK_EX|LOCK_NB) < 0)
-# endif
+       if (!lockfile(fileno(qfp), qf, LOCK_EX|LOCK_NB))
        {
        {
-               if (errno == EWOULDBLOCK)
-               {
-                       /* being processed by another queuer */
-                       if (Verbose)
-                               printf("%s: locked\n", e->e_id);
+               /* being processed by another queuer */
+               if (Verbose)
+                       printf("%s: locked\n", e->e_id);
 # ifdef LOG
 # ifdef LOG
-                       if (LogLevel > 19)
-                               syslog(LOG_DEBUG, "%s: locked", e->e_id);
+               if (LogLevel > 19)
+                       syslog(LOG_DEBUG, "%s: locked", e->e_id);
 # endif /* LOG */
 # endif /* LOG */
-               }
-               else
-               {
-                       syserr("%s: flock failure", e->e_id);
-               }
                (void) fclose(qfp);
                return FALSE;
        }
                (void) fclose(qfp);
                return FALSE;
        }
@@ -1115,10 +1088,8 @@ printqueue()
                auto time_t submittime = 0;
                long dfsize = -1;
                char message[MAXLINE];
                auto time_t submittime = 0;
                long dfsize = -1;
                char message[MAXLINE];
-# ifdef LOCKF
-               struct flock lfd;
-# endif
                extern bool shouldqueue();
                extern bool shouldqueue();
+               extern bool lockfile();
 
                f = fopen(w->w_name, "r");
                if (f == NULL)
 
                f = fopen(w->w_name, "r");
                if (f == NULL)
@@ -1127,13 +1098,7 @@ printqueue()
                        continue;
                }
                printf("%7s", w->w_name + 2);
                        continue;
                }
                printf("%7s", w->w_name + 2);
-# ifdef LOCKF
-               lfd.l_type = F_RDLCK;
-               lfd.l_whence = lfd.l_start = lfd.l_len = 0;
-               if (fcntl(fileno(f), F_GETLK, &lfd) < 0 || lfd.l_type != F_UNLCK)
-# else
-               if (flock(fileno(f), LOCK_SH|LOCK_NB) < 0)
-# endif
+               if (!lockfile(fileno(f), w->w_name, LOCK_SH|LOCK_NB))
                        printf("*");
                else if (shouldqueue(w->w_pri, w->w_ctime))
                        printf("X");
                        printf("*");
                else if (shouldqueue(w->w_pri, w->w_ctime))
                        printf("X");
@@ -1224,10 +1189,11 @@ queuename(e, type)
        register ENVELOPE *e;
        char type;
 {
        register ENVELOPE *e;
        char type;
 {
-       static char buf[MAXNAME];
        static int pid = -1;
        static char c1 = 'A';
        static char c2 = 'A';
        static int pid = -1;
        static char c1 = 'A';
        static char c2 = 'A';
+       static char buf[MAXNAME];
+       extern bool lockfile();
 
        if (e->e_id == NULL)
        {
 
        if (e->e_id == NULL)
        {
@@ -1246,9 +1212,6 @@ queuename(e, type)
                while (c1 < '~' || c2 < 'Z')
                {
                        int i;
                while (c1 < '~' || c2 < 'Z')
                {
                        int i;
-# ifdef LOCKF
-                       struct flock lfd;
-# endif
 
                        if (c2 >= 'Z')
                        {
 
                        if (c2 >= 'Z')
                        {
@@ -1269,13 +1232,7 @@ queuename(e, type)
                                        qf, QueueDir);
                                exit(EX_UNAVAILABLE);
                        }
                                        qf, QueueDir);
                                exit(EX_UNAVAILABLE);
                        }
-# ifdef LOCKF
-                       lfd.l_type = F_WRLCK;
-                       lfd.l_whence = lfd.l_start = lfd.l_len = 0;
-                       if (fcntl(i, F_SETLK, &lfd) >= 0)
-# else
-                       if (flock(i, LOCK_EX|LOCK_NB) >= 0)
-# endif
+                       if (lockfile(i, qf, LOCK_EX|LOCK_NB))
                        {
                                e->e_lockfp = fdopen(i, "w");
                                break;
                        {
                                e->e_lockfp = fdopen(i, "w");
                                break;
index 55b7518..c8915d2 100644 (file)
@@ -7,12 +7,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        6.27 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        6.28 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 # include <sys/stat.h>
 #endif /* not lint */
 
 # include "sendmail.h"
 # include <sys/stat.h>
-# include <fcntl.h>
 # include <pwd.h>
 
 /*
 # include <pwd.h>
 
 /*
index e9e90ca..029e567 100644 (file)
@@ -8,9 +8,9 @@
 
 #ifndef lint
 #ifdef USERDB
 
 #ifndef lint
 #ifdef USERDB
-static char sccsid [] = "@(#)udb.c     6.12 (Berkeley) %G% (with USERDB)";
+static char sccsid [] = "@(#)udb.c     6.13 (Berkeley) %G% (with USERDB)";
 #else
 #else
-static char sccsid [] = "@(#)udb.c     6.12 (Berkeley) %G% (without USERDB)";
+static char sccsid [] = "@(#)udb.c     6.13 (Berkeley) %G% (without USERDB)";
 #endif
 #endif
 
 #endif
 #endif
 
@@ -20,7 +20,6 @@ static char sccsid [] = "@(#)udb.c    6.12 (Berkeley) %G% (without USERDB)";
 
 #include <sys/time.h>
 #include <errno.h>
 
 #include <sys/time.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <netdb.h>
 #include <db.h>
 
 #include <netdb.h>
 #include <db.h>
 
index 5085823..a5ec058 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     6.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     6.13 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -505,16 +505,15 @@ dfopen(filename, mode)
        }
        if (fp != NULL)
        {
        }
        if (fp != NULL)
        {
-#ifdef FLOCK
                int locktype;
                int locktype;
+               extern bool lockfile();
 
                /* lock the file to avoid accidental conflicts */
                if (*mode == 'w' || *mode == 'a')
                        locktype = LOCK_EX;
                else
                        locktype = LOCK_SH;
 
                /* lock the file to avoid accidental conflicts */
                if (*mode == 'w' || *mode == 'a')
                        locktype = LOCK_EX;
                else
                        locktype = LOCK_SH;
-               (void) flock(fileno(fp), locktype);
-#endif
+               (void) lockfile(fileno(fp), filename, locktype);
                errno = 0;
        }
        return (fp);
                errno = 0;
        }
        return (fp);