]> arthur.barton.de Git - netatalk.git/commitdiff
Fix a bug in the new DB_RECOVER code that allowed for multiple clients
authorjmarcus <jmarcus>
Mon, 10 Dec 2001 18:39:00 +0000 (18:39 +0000)
committerjmarcus <jmarcus>
Mon, 10 Dec 2001 18:39:00 +0000 (18:39 +0000)
to open the same DB ENV with DB_RECOVER.

libatalk/cnid/cnid_open.c

index 910e6aa19af54c91a2601cb474eabbdb3e1dc96c..305768901d7b2930ef09ada66cfaf4e9046e5388 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_open.c,v 1.23 2001-12-10 03:51:56 jmarcus Exp $
+ * $Id: cnid_open.c,v 1.24 2001-12-10 18:39:00 jmarcus Exp $
  *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
@@ -234,24 +234,8 @@ void *cnid_open(const char *dir) {
        strcat(path, "/");
        len++;
 
-       /* Create a file to represent database recovery.  While this file
-        * exists, the database is being recovered, and all other clients will
-        * sleep until recovery is complete, and this file goes away. */
        strcpy(recover_file, path);
        strcat(recover_file, DBRECOVERFILE);
-       if (!have_lock) {
-               if (stat(recover_file, &rsb) < 0) {
-                       if ((rfd = open(recover_file, O_RDWR | O_CREAT, 0666)) > -1) {
-                       DBEXTRAS |= DB_RECOVER;
-                               have_lock = 1;
-                       }
-               }
-               else {
-                       while(stat(recover_file, &rsb) == 0) {
-                               sleep(1);
-                       }
-               }
-       }
 
     /* Search for a byte lock.  This allows us to cleanup the log files
      * at cnid_close() in a clean fashion.
@@ -275,6 +259,23 @@ void *cnid_open(const char *dir) {
         syslog(LOG_ERR, "cnid_open: Cannot establish logfile cleanup lock for database environment %s (open() failed)", path);
     }
 
+       /* Create a file to represent database recovery.  While this file
+        * exists, the database is being recovered, and all other clients will
+        * sleep until recovery is complete, and this file goes away. */
+       if (!have_lock && db->lockfd > -1 && lock.l_start == 0) {
+               if (stat(recover_file, &rsb) < 0) {
+                       if ((rfd = open(recover_file, O_RDWR | O_CREAT, 0666)) > -1) {
+                       DBEXTRAS |= DB_RECOVER;
+                               have_lock = 1;
+                       }
+               }
+               else {
+                       while(stat(recover_file, &rsb) == 0) {
+                               sleep(1);
+                       }
+               }
+       }
+
     path[len + DBHOMELEN] = '\0';
     open_flag = DB_CREATE;