fix for bug #578 repl leaks umask; there are several other
[mmh] / sbr / lock_file.c
index ec88737..7280464 100644 (file)
@@ -3,6 +3,10 @@
  * lock.c -- routines to lock/unlock files
  *
  * $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 /* Modified by Ruud de Rooij to support Miquel van Smoorenburg's liblockfile
@@ -419,9 +423,18 @@ lockit (struct lockinfo *li)
     curlock = li->curlock;
     tmplock = li->tmplock;
 
+#ifdef HAVE_MKSTEMP
+    if ((fd = mkstemp(tmplock)) == -1)
+       return -1;
+#else
+    if (mktemp(tmplock) == NULL)
+       return -1;
+    if (unlink(tmplock) == -1 && errno != ENOENT)
+       return -1;
     /* create the temporary lock file */
     if ((fd = creat(tmplock, 0600)) == -1)
        return -1;
+#endif
 
 #if 0
     /* write our process id into lock file */
@@ -501,18 +514,6 @@ lockname (char *file, struct lockinfo *li, int isnewlock)
        else
            snprintf (li->tmplock, sizeof(li->tmplock), "%.*s,LCK.XXXXXX",
                     cp - li->curlock, li->curlock);
-/*
-  Mkstemp work postponed until later -Doug
-#ifdef HAVE_MKSTEMP
-       mkstemp (li->tmplock);
-#else
-*/
-       mktemp (li->tmplock);
-/*
-#endif
-*/
-
-       unlink (li->tmplock);   /* remove any stray */
     }
 #endif
 }