]> granicus.if.org Git - mutt/commitdiff
Impose a hard limit on dotlock attempts.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 26 Jul 1999 21:04:15 +0000 (21:04 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 26 Jul 1999 21:04:15 +0000 (21:04 +0000)
dotlock.c

index a9b891dd3fd749f19258abcaf1b8a5802f0da847..5dfc2923a7c0b6499b898012df0d9fe76fef00c4 100644 (file)
--- a/dotlock.c
+++ b/dotlock.c
@@ -563,6 +563,8 @@ dotlock_deference_symlink(char *d, size_t l, const char *path)
  * 
  */
 
+#define HARDMAXATTEMPTS 10
+
 static int
 dotlock_lock(const char *realpath)
 {
@@ -571,6 +573,7 @@ dotlock_lock(const char *realpath)
   size_t prev_size = 0;
   int fd;
   int count = 0;
+  int hard_count = 0;
   struct stat sb;
   time_t t;
   
@@ -603,25 +606,25 @@ dotlock_lock(const char *realpath)
   
   close(fd);
   
-  while(1)
+  while (hard_count++ < HARDMAXATTEMPTS)
   {
 
     BEGIN_PRIVILEGED();
-    link(nfslockfile, lockfile);
+    link (nfslockfile, lockfile);
     END_PRIVILEGED();
 
-    if(stat(nfslockfile, &sb) != 0)
+    if (stat(nfslockfile, &sb) != 0)
     {
       /* perror("stat"); */
       return DL_EX_ERROR;
     }
-    
+
     if(sb.st_nlink == 2)
       break;
-    
+
     if(count == 0)
       prev_size = sb.st_size;
-    
+
     if(prev_size == sb.st_size && ++count > Retry)
     {
       if(f_force)
@@ -653,7 +656,7 @@ dotlock_lock(const char *realpath)
       sleep(1);
     } while (time(NULL) == t);
   }
-  
+
   BEGIN_PRIVILEGED();
   unlink(nfslockfile);
   END_PRIVILEGED();