/*
- * $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
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));
}
}
}
/*
- * $Id: cnid_open.c,v 1.27 2001-12-13 03:31:34 jmarcus Exp $
+ * $Id: cnid_open.c,v 1.28 2001-12-14 03:10:37 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#define DBLONGNAME "longname.db" /* did/unicode mapping */
#define DBLOCKFILE "cnid.lock"
#define DBRECOVERFILE "cnid.dbrecover"
+#define DBCLOSEFILE "cnid.close"
#define DBHOMELEN 8
#define DBLEN 10
static int have_lock = 0;
void *cnid_open(const char *dir) {
- struct stat st, rsb;
+ struct stat st, rsb, csb;
struct flock lock;
char path[MAXPATHLEN + 1];
char recover_file[MAXPATHLEN + 1];
strcat(path, "/");
len++;
+ strcpy(db->close_file, path);
+ strcat(db->close_file, DBCLOSEFILE);
+
+ /* Check to make sure that a client isn't in the process of closing
+ * the database environment. To do this, sleep on the close file. */
+ while(stat(db->close_file, &csb) == 0) {
+ sleep(1);
+ }
+
strcpy(recover_file, path);
strcat(recover_file, DBRECOVERFILE);
if (db->lockfd > -1) {
close(db->lockfd);
}
+ if (rfd > -1) {
+ (void)remove(recover_file);
+ close(rfd);
+ }
fail_adouble: