From: Jonathan McDowell Date: Tue, 15 Jan 2008 22:24:17 +0000 (+0000) Subject: Fix db4 backend - we weren't actually providing a suitable dbfuncs struct. X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/3561aed8483fe3076c7689f93fbc94ca63de77b3 Fix db4 backend - we weren't actually providing a suitable dbfuncs struct. --- diff --git a/keydb_db4.c b/keydb_db4.c index 2f6033a..986c49a 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -122,6 +122,39 @@ static void db4_endtrans(void) return; } +/** + * cleanupdb - De-initialize the key database. + * + * This function should be called upon program exit to allow the DB to + * cleanup after itself. + */ +static void db4_cleanupdb(void) +{ + int i = 0; + + if (dbenv != NULL) { + dbenv->txn_checkpoint(dbenv, 0, 0, 0); + if (id32db != NULL) { + id32db->close(id32db, 0); + id32db = NULL; + } + if (worddb != NULL) { + worddb->close(worddb, 0); + worddb = NULL; + } + for (i = 0; i < numdbs; i++) { + if (dbconns[i] != NULL) { + dbconns[i]->close(dbconns[i], 0); + dbconns[i] = NULL; + } + } + free(dbconns); + dbconns = NULL; + dbenv->close(dbenv, 0); + dbenv = NULL; + } +} + /** * initdb - Initialize the key database. * @@ -290,7 +323,7 @@ static void db4_initdb(bool readonly) } if (ret != 0) { - cleanupdb(); + db4_cleanupdb(); logthing(LOGTHING_CRITICAL, "Error opening database; exiting"); exit(EXIT_FAILURE); @@ -299,39 +332,6 @@ static void db4_initdb(bool readonly) return; } -/** - * cleanupdb - De-initialize the key database. - * - * This function should be called upon program exit to allow the DB to - * cleanup after itself. - */ -static void db4_cleanupdb(void) -{ - int i = 0; - - if (dbenv != NULL) { - dbenv->txn_checkpoint(dbenv, 0, 0, 0); - if (id32db != NULL) { - id32db->close(id32db, 0); - id32db = NULL; - } - if (worddb != NULL) { - worddb->close(worddb, 0); - worddb = NULL; - } - for (i = 0; i < numdbs; i++) { - if (dbconns[i] != NULL) { - dbconns[i]->close(dbconns[i], 0); - dbconns[i] = NULL; - } - } - free(dbconns); - dbconns = NULL; - dbenv->close(dbenv, 0); - dbenv = NULL; - } -} - /** * fetch_key - Given a keyid fetch the key from storage. * @keyid: The keyid to fetch. @@ -1067,3 +1067,20 @@ static uint64_t db4_getfullkeyid(uint64_t keyid) #define NEED_KEYID2UID 1 #define NEED_UPDATEKEYS 1 #include "keydb.c" + +struct dbfuncs keydb_db4_funcs = { + .initdb = db4_initdb, + .cleanupdb = db4_cleanupdb, + .starttrans = db4_starttrans, + .endtrans = db4_endtrans, + .fetch_key = db4_fetch_key, + .fetch_key_text = db4_fetch_key_text, + .store_key = db4_store_key, + .update_keys = generic_update_keys, + .delete_key = db4_delete_key, + .getkeysigs = generic_getkeysigs, + .cached_getkeysigs = generic_cached_getkeysigs, + .keyid2uid = generic_keyid2uid, + .getfullkeyid = db4_getfullkeyid, + .iterate_keys = db4_iterate_keys, +};