2 * $Id: cnid_close.c,v 1.19 2002-01-04 04:45:48 sibaz Exp $
7 #endif /* HAVE_CONFIG_H */
12 #endif /* HAVE_UNISTD_H */
15 #endif /* HAVE_FCNTL_H */
17 #include <atalk/logger.h>
22 #include <atalk/cnid.h>
24 #include "cnid_private.h"
26 void cnid_close(void *CNID) {
34 /* Flush the transaction log and delete the log file if we can. */
35 if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
38 lock.l_type = F_WRLCK;
39 lock.l_whence = SEEK_SET;
40 lock.l_start = lock.l_len = 0;
41 if (fcntl(db->lockfd, F_SETLK, &lock) == 0) {
45 if ((cfd = open(db->close_file, O_RDWR | O_CREAT, 0666)) > -1) {
47 /* Checkpoint the databases until we can checkpoint no
49 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
50 while (rc == DB_INCOMPLETE) {
51 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
54 #if DB_VERSION_MINOR > 2
55 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS)) != 0) {
56 #else /* DB_VERSION_MINOR < 2 */
57 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG | DB_ARCH_ABS, NULL)) != 0) {
58 #endif /* DB_VERSION_MINOR */
59 LOG(log_error, logtype_default, "cnid_close: Unable to archive logfiles: %s",
64 for (first = list; *list != NULL; ++list) {
65 if ((rc = remove(*list)) != 0) {
67 LOG(log_info, logtype_default, "cnid_close: failed to remove %s: %s",
74 (void)remove(db->close_file);
78 LOG(log_error, logtype_default, "cnid_close: Failed to open database closing lock file: %s", strerror(errno));
83 db->db_didname->close(db->db_didname, 0);
84 db->db_devino->close(db->db_devino, 0);
85 db->db_cnid->close(db->db_cnid, 0);
86 db->dbenv->close(db->dbenv, 0);
88 if (db->lockfd > -1) {
89 close(db->lockfd); /* This will also release any locks we have. */