From 77d65dee2a1304235b2a25afb778155c13779780 Mon Sep 17 00:00:00 2001 From: jmarcus Date: Thu, 13 Dec 2001 02:39:37 +0000 Subject: [PATCH] Fix a bug where certain clients may sleep forever trying to connect to the server if for some reason a controlling afpd quit before removing the recover.cnid file. Also, do a full checkpoint when the last client disconnects, and remove any logfiles that might be lingering around. --- libatalk/cnid/cnid_close.c | 15 +++++++++++---- libatalk/cnid/cnid_open.c | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/libatalk/cnid/cnid_close.c b/libatalk/cnid/cnid_close.c index 4858ff83..1200e211 100644 --- a/libatalk/cnid/cnid_close.c +++ b/libatalk/cnid/cnid_close.c @@ -1,5 +1,5 @@ /* - * $Id: cnid_close.c,v 1.14 2001-12-10 03:51:56 jmarcus Exp $ + * $Id: cnid_close.c,v 1.15 2001-12-13 02:39:37 jmarcus Exp $ */ #ifdef HAVE_CONFIG_H @@ -45,12 +45,19 @@ void cnid_close(void *CNID) { lock.l_start = lock.l_len = 0; if (fcntl(db->lockfd, F_SETLK, &lock) == 0) { char **list, **first; - + + /* 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); + } + chdir(db->dbenv->db_log_dir ? db->dbenv->db_log_dir : db->dbenv->db_home); #if DB_VERSION_MINOR > 2 - if ((rc = log_archive(db->dbenv, &list, 0)) != 0) { + if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG)) != 0) { #else /* DB_VERSION_MINOR < 2 */ - if ((rc = log_archive(db->dbenv, &list, 0, NULL)) != 0) { + if ((rc = log_archive(db->dbenv, &list, DB_ARCH_LOG, NULL)) != 0) { #endif /* DB_VERSION_MINOR */ syslog(LOG_ERR, "cnid_close: Unable to archive logfiles: %s", db_strerror(rc)); diff --git a/libatalk/cnid/cnid_open.c b/libatalk/cnid/cnid_open.c index 348ebe86..14a2c27f 100644 --- a/libatalk/cnid/cnid_open.c +++ b/libatalk/cnid/cnid_open.c @@ -1,5 +1,5 @@ /* - * $Id: cnid_open.c,v 1.25 2001-12-10 22:55:13 jmarcus Exp $ + * $Id: cnid_open.c,v 1.26 2001-12-13 02:39:37 jmarcus Exp $ * * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -263,11 +263,12 @@ void *cnid_open(const char *dir) { * exists, the database is being recovered, and all other clients will * sleep until recovery is complete, and this file goes away. */ if (!have_lock && db->lockfd > -1 && lock.l_start == 0) { - if (stat(recover_file, &rsb) < 0) { - if ((rfd = open(recover_file, O_RDWR | O_CREAT, 0666)) > -1) { - DBEXTRAS |= DB_RECOVER; - have_lock = 1; - } + if (stat(recover_file, &rsb) == 0) { + (void)remove(recover_file); + } + if ((rfd = open(recover_file, O_RDWR | O_CREAT, 0666)) > -1) { + DBEXTRAS |= DB_RECOVER; + have_lock = 1; } } else if (!have_lock) { @@ -329,8 +330,16 @@ void *cnid_open(const char *dir) { /* If we have the recovery lock, close the file, remove it, so other * clients can proceed opening the DB environment. */ if (rfd > -1) { - close(rfd); (void)remove(recover_file); + switch(errno) { + case 0: + case ENOENT: + break; + default: + syslog(LOG_ERR, "cnid_open: Unable to remove %s: %s", + recover_file, strerror(errno)); + } + close(rfd); rfd = -1; } -- 2.39.2