]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/cnid/cnid_close.c
Hopefully fix a problem when multiple clients mount and unmount a volume
[netatalk.git] / libatalk / cnid / cnid_close.c
index 232a6cf9c373284f2e7e775fcba3f775169e26bb..133bf73719b12c533be22f48a6ffafbf78fe600f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_close.c,v 1.17 2001-12-13 15:15:05 jmarcus Exp $
+ * $Id: cnid_close.c,v 1.18 2001-12-14 03:10:37 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -40,33 +40,42 @@ void cnid_close(void *CNID) {
         lock.l_start = lock.l_len = 0;
         if (fcntl(db->lockfd, F_SETLK, &lock) == 0) {
             char **list, **first;
+            int cfd = -1;
 
-            /* Checkpoint the databases until we can checkpoint no
-             * more. */
-            rc = txn_checkpoint(db->dbenv, 0, 0, 0);
-            while (rc == DB_INCOMPLETE) {
+            if ((cfd = open(db->close_file, O_RDWR | O_CREAT, 0666)) > -1) {
+
+                /* Checkpoint the databases until we can checkpoint no
+                 * more. */
                 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
-            }
+                while (rc == DB_INCOMPLETE) {
+                    rc = txn_checkpoint(db->dbenv, 0, 0, 0);
+                }
 
 #if DB_VERSION_MINOR > 2
-            if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS)) != 0) {
+                if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS)) != 0) {
 #else /* DB_VERSION_MINOR < 2 */
-            if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS, NULL)) != 0) {
+                if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS, NULL)) != 0) {
 #endif /* DB_VERSION_MINOR */
-                syslog(LOG_ERR, "cnid_close: Unable to archive logfiles: %s",
-                       db_strerror(rc));
-            }
+                    syslog(LOG_ERR, "cnid_close: Unable to archive logfiles: %s",
+                           db_strerror(rc));
+                }
 
-            if (list != NULL) {
-                for (first = list; *list != NULL; ++list) {
-                    if ((rc = remove(*list)) != 0) {
+                if (list != NULL) {
+                    for (first = list; *list != NULL; ++list) {
+                        if ((rc = remove(*list)) != 0) {
 #ifdef DEBUG
-                        syslog(LOG_INFO, "cnid_close: failed to remove %s: %s",
-                               *list, strerror(rc));
+                            syslog(LOG_INFO, "cnid_close: failed to remove %s: %s",
+                                   *list, strerror(rc));
 #endif
+                        }
                     }
+                    free(first);
                 }
-                free(first);
+                (void)remove(db->close_file);
+                close(cfd);
+            }
+            else {
+                syslog(LOG_ERR, "cnid_close: Failed to open database closing lock file: %s", strerror(errno));
             }
         }
     }