2 * $Id: cnid_db3_close.c,v 1.1.4.1 2003-09-09 16:42:21 didg 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>
23 #include "cnid_db3_private.h"
26 void cnid_db3_close(struct _cnid_db *cdb) {
31 LOG(log_error, logtype_afpd, "cnid_close called with NULL argument !");
35 if (!(db = cdb->_private)) {
39 /* Flush the transaction log and delete the log file if we can. */
40 if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
43 lock.l_type = F_WRLCK;
44 lock.l_whence = SEEK_SET;
45 lock.l_start = lock.l_len = 0;
46 if (fcntl(db->lockfd, F_SETLK, &lock) == 0) {
50 /* Checkpoint the databases until we can checkpoint no
52 #if DB_VERSION_MAJOR >= 4
53 #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1
54 db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
56 rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
57 #endif /* DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 */
59 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
60 #endif /* DB_VERSION_MAJOR >= 4 */
61 #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1)
62 while (rc == DB_INCOMPLETE) {
63 #if DB_VERSION_MAJOR >= 4
64 rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
66 rc = txn_checkpoint(db->dbenv, 0, 0, 0);
67 #endif /* DB_VERSION_MAJOR >= 4 */
69 #endif /* DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1) */
71 #if DB_VERSION_MAJOR >= 4
72 if ((rc = db->dbenv->log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
73 #elif DB_VERSION_MINOR > 2
74 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
75 #else /* DB_VERSION_MINOR < 2 */
76 if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS, NULL)) != 0) {
77 #endif /* DB_VERSION_MINOR */
78 LOG(log_error, logtype_default, "cnid_close: Unable to archive logfiles: %s", db_strerror(rc));
82 for (first = list; *list != NULL; ++list) {
83 if ((rc = remove(*list)) != 0) {
85 LOG(log_info, logtype_default, "cnid_close: failed to remove %s: %s", *list, strerror(rc));
92 (void)remove(db->lock_file);
95 db->db_didname->close(db->db_didname, 0);
96 db->db_devino->close(db->db_devino, 0);
97 db->db_cnid->close(db->db_cnid, 0);
98 db->dbenv->close(db->dbenv, 0);
100 if (db->lockfd > -1) {
101 close(db->lockfd); /* This will also release any locks we have. */
109 #endif /* CNID_BACKEND_DB3 */