]> granicus.if.org Git - mutt/commitdiff
Locking fix.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 24 Jan 2000 13:17:16 +0000 (13:17 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 24 Jan 2000 13:17:16 +0000 (13:17 +0000)
dotlock.c
dotlock.h
mx.c

index 3f35d37d0597aa3e1381be055a2e61b80037f2f0..1ef730702402b23b2dd178b9603e3793943aa438 100644 (file)
--- a/dotlock.c
+++ b/dotlock.c
@@ -103,9 +103,9 @@ static gid_t MailGid;
 #endif
 
 static int dotlock_deference_symlink (char *, size_t, const char *);
-static int dotlock_prepare (char *, size_t, const char *);
+static int dotlock_prepare (char *, size_t, const char *, int fd);
 static int dotlock_check_stats (struct stat *, struct stat *);
-static int dotlock_dispatch (const char *);
+static int dotlock_dispatch (const char *, int fd);
 
 #ifdef DL_STANDALONE
 static int dotlock_init_privs (void);
@@ -176,7 +176,7 @@ int main (int argc, char **argv)
   if (optind == argc || Retry < 0)
     usage (argv[0]);
 
-  return dotlock_dispatch (argv[optind]);
+  return dotlock_dispatch (argv[optind], -1);
 }
 
 
@@ -217,7 +217,7 @@ dotlock_init_privs (void)
  * mutt instead of mx.c's invoke_dotlock ().
  */
 
-int dotlock_invoke (const char *path, int flags, int retry)
+int dotlock_invoke (const char *path, int fd, int flags, int retry)
 {
   int currdir;
   int r;
@@ -232,7 +232,7 @@ int dotlock_invoke (const char *path, int flags, int retry)
   else
     Retry = 0;
   
-  r = dotlock_dispatch (path);
+  r = dotlock_dispatch (path, fd);
   
   fchdir (currdir);
   close (currdir);
@@ -243,7 +243,7 @@ int dotlock_invoke (const char *path, int flags, int retry)
 #endif  /* DL_STANDALONE */
 
 
-static int dotlock_dispatch (const char *f)
+static int dotlock_dispatch (const char *f, int fd)
 {
   char realpath[_POSIX_PATH_MAX];
 
@@ -258,7 +258,7 @@ static int dotlock_dispatch (const char *f)
    * lengthy comment below.
    */
 
-  if (dotlock_prepare (realpath, sizeof (realpath), f) != 0)
+  if (dotlock_prepare (realpath, sizeof (realpath), f, fd) != 0)
     return DL_EX_ERROR;
 
   /* Actually perform the locking operation. */
@@ -433,7 +433,7 @@ dotlock_check_stats (struct stat *fsb, struct stat *lsb)
 }
 
 static int
-dotlock_prepare (char *bn, size_t l, const char *f)
+dotlock_prepare (char *bn, size_t l, const char *f, int _fd)
 {
   struct stat fsb, lsb;
   char realpath[_POSIX_PATH_MAX];
@@ -464,12 +464,16 @@ dotlock_prepare (char *bn, size_t l, const char *f)
   
   if (chdir (dirname) == -1)
     return -1;
-  
-  if ((fd = open (basename, O_RDONLY)) == -1)
+
+  if (_fd != -1)
+    fd = _fd;
+  else if ((fd = open (basename, O_RDONLY)) == -1)
     return -1;
   
   r = fstat (fd, &fsb);
-  close (fd);
+  
+  if (_fd == -1)
+    close (fd);
   
   if (r == -1)
     return -1;
index 2d2d54112e94862602efcae5085a3ca50403b7bc..1105dc1c1f83f1db31c120b294b26246256ad66f 100644 (file)
--- a/dotlock.h
+++ b/dotlock.h
@@ -40,7 +40,7 @@
 #define DL_FL_ACTIONS (DL_FL_TRY|DL_FL_UNLOCK|DL_FL_UNLINK)
 
 #ifndef DL_STANDALONE
-int dotlock_invoke (const char *, int, int);
+int dotlock_invoke (const char *, int, int, int);
 #endif
 
 #endif
diff --git a/mx.c b/mx.c
index 759971966992341672370fa258413aa5cc555382..d8b7bc0b7fa42ec691749cb513916eb2d6f72d51 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -66,7 +66,7 @@
 
 #ifdef DL_STANDALONE
 
-static int invoke_dotlock (const char *path, int flags, int retry)
+static int invoke_dotlock (const char *path, int dummy, int flags, int retry)
 {
   char cmd[LONG_STRING + _POSIX_PATH_MAX];
   char f[SHORT_STRING + _POSIX_PATH_MAX];
@@ -97,7 +97,7 @@ static int invoke_dotlock (const char *path, int flags, int retry)
 
 #endif
 
-static int dotlock_file (const char *path, int retry)
+static int dotlock_file (const char *path, int fd, int retry)
 {
   int r;
   int flags = DL_FL_USEPRIV | DL_FL_RETRY;
@@ -105,7 +105,7 @@ static int dotlock_file (const char *path, int retry)
   if (retry) retry = 1;
 
 retry_lock:
-  if ((r = invoke_dotlock(path, flags, retry)) == DL_EX_EXIST)
+  if ((r = invoke_dotlock(path, fd, flags, retry)) == DL_EX_EXIST)
   {
     if (!option (OPTNOCURSES))
     {
@@ -129,9 +129,9 @@ retry_lock:
   return (r == DL_EX_OK ? 0 : -1);
 }
 
-static int undotlock_file (const char *path)
+static int undotlock_file (const char *path, int fd)
 {
-  return (invoke_dotlock(path, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == DL_EX_OK ? 
+  return (invoke_dotlock(path, fd, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == DL_EX_OK ? 
          0 : -1);
 }
 
@@ -229,7 +229,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout)
 
 #ifdef USE_DOTLOCK
   if (r == 0 && dot)
-    r = dotlock_file (path,timeout);
+    r = dotlock_file (path, fd, timeout);
 #endif /* USE_DOTLOCK */
 
   if (r == -1)
@@ -268,7 +268,7 @@ int mx_unlock_file (const char *path, int fd, int dot)
 
 #ifdef USE_DOTLOCK
   if (dot)
-    undotlock_file (path);
+    undotlock_file (path, fd);
 #endif
   
   return 0;
@@ -308,7 +308,7 @@ void mx_unlink_empty (const char *path)
   }
 
 #ifdef USE_DOTLOCK
-  invoke_dotlock (path, DL_FL_UNLINK, 1);
+  invoke_dotlock (path, fd, DL_FL_UNLINK, 1);
 #else
   if (fstat (fd, &sb) == 0 && sb.st_size == 0)
     unlink (path);