2 * $Id: cnid_db3_close.c,v 1.2 2005-04-28 20:49:59 bfernhomberg Exp $
7 #endif /* HAVE_CONFIG_H */
9 #ifdef CNID_BACKEND_DB3
13 #endif /* HAVE_UNISTD_H */
16 #endif /* HAVE_FCNTL_H */
18 #include <atalk/logger.h>
27 #include "cnid_db3_private.h"
30 void cnid_db3_close(struct _cnid_db *cdb) {
35 LOG(log_error, logtype_afpd, "cnid_close called with NULL argument !");
39 if (!(db = cdb->_private)) {
43 /* Flush the transaction log and delete the log file if we can. */
44 if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
47 lock.l_type = F_WRLCK;
48 lock.l_whence = SEEK_SET;
49 lock.l_start = lock.l_len = 0;
50 if (fcntl(db->lockfd, F_SETLK, &lock) == 0) {
54 /* Checkpoint the databases until we can checkpoint no
56 #if DB_VERSION_MAJOR >= 4
57 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1
58 db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
60 rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
61 #endif /* DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 */
63 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
64 #endif /* DB_VERSION_MAJOR >= 4 */
65 #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1)
66 while (rc == DB_INCOMPLETE) {
67 #if DB_VERSION_MAJOR >= 4
68 rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
70 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
71 #endif /* DB_VERSION_MAJOR >= 4 */
73 #endif /* DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1) */
75 #if DB_VERSION_MAJOR >= 4
76 if ((rc = db->dbenv->log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
77 #elif DB_VERSION_MINOR > 2
78 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
79 #else /* DB_VERSION_MINOR < 2 */
80 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS, NULL)) != 0) {
81 #endif /* DB_VERSION_MINOR */
82 LOG(log_error, logtype_default, "cnid_close: Unable to archive logfiles: %s", db_strerror(rc));
86 for (first = list; *list != NULL; ++list) {
87 if ((rc = remove(*list)) != 0) {
89 LOG(log_info, logtype_default, "cnid_close: failed to remove %s: %s", *list, strerror(rc));
96 (void)remove(db->lock_file);
99 db->db_didname->close(db->db_didname, 0);
100 db->db_devino->close(db->db_devino, 0);
101 db->db_cnid->close(db->db_cnid, 0);
102 db->dbenv->close(db->dbenv, 0);
104 if (db->lockfd > -1) {
105 close(db->lockfd); /* This will also release any locks we have. */
113 #endif /* CNID_BACKEND_DB3 */