From b927ce30d9f6582f926f94d3da9b7e3af56c6bcf Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 9 Aug 2023 11:47:02 -0400 Subject: [PATCH] berkeley_db.c: prefixed all module-local functions with bdb_ to avoid namespace collisions --- .../server/backends/berkeley_db/berkeley_db.c | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/citadel/server/backends/berkeley_db/berkeley_db.c b/citadel/server/backends/berkeley_db/berkeley_db.c index edf7a902c..b16c0e57d 100644 --- a/citadel/server/backends/berkeley_db/berkeley_db.c +++ b/citadel/server/backends/berkeley_db/berkeley_db.c @@ -35,6 +35,7 @@ static DB *dbp[MAXCDB]; // One DB handle for each Citadel database static DB_ENV *dbenv; // The DB environment (global) +// Called by other functions in this module to GTFO quickly if we need to. Not part of the backend API. void bdb_abort(void) { syslog(LOG_DEBUG, "bdb: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d", getuid(), getgid(), geteuid(), getegid() @@ -44,7 +45,7 @@ void bdb_abort(void) { } -// Verbose logging callback +// Verbose logging callback for Berkeley DB. Not part of the backend API. void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) { if (!IsEmptyStr(msg)) { syslog(LOG_DEBUG, "bdb: %s %s", msg, foo); @@ -52,14 +53,14 @@ void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) { } -// Verbose logging callback +// Verbose error logging callback for Berkeley DB. Not part of the backend API. void bdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) { syslog(LOG_ERR, "bdb: %s", msg); } // wrapper for txn_abort() that logs/aborts on error -static void txabort(DB_TXN *tid) { +static void bdb_txabort(DB_TXN *tid) { int ret; ret = tid->abort(tid); @@ -72,7 +73,7 @@ static void txabort(DB_TXN *tid) { // wrapper for txn_commit() that logs/aborts on error -static void txcommit(DB_TXN *tid) { +static void bdb_txcommit(DB_TXN *tid) { int ret; ret = tid->commit(tid, 0); @@ -85,7 +86,7 @@ static void txcommit(DB_TXN *tid) { // wrapper for txn_begin() that logs/aborts on error -static void txbegin(DB_TXN **tid) { +static void bdb_txbegin(DB_TXN **tid) { int ret; ret = dbenv->txn_begin(dbenv, NULL, tid, 0); @@ -98,13 +99,13 @@ static void txbegin(DB_TXN **tid) { // panic callback -static void dbpanic(DB_ENV *env, int errval) { +static void bdb_dbpanic(DB_ENV *env, int errval) { syslog(LOG_ERR, "bdb: PANIC: %s", db_strerror(errval)); bdb_abort(); } -static void cclose(DBC *cursor) { +static void bdb_cclose(DBC *cursor) { int ret; if ((ret = cursor->c_close(cursor))) { @@ -114,7 +115,7 @@ static void cclose(DBC *cursor) { } -static void bailIfCursor(DBC **cursors, const char *msg) { +static void bdb_bailIfCursor(DBC **cursors, const char *msg) { int i; for (i = 0; i < MAXCDB; i++) @@ -126,7 +127,7 @@ static void bailIfCursor(DBC **cursors, const char *msg) { void bdb_check_handles(void) { - bailIfCursor(TSD->cursors, "in check_handles"); + bdb_bailIfCursor(TSD->cursors, "in check_handles"); if (TSD->tid != NULL) { syslog(LOG_ERR, "bdb: transaction still in progress!"); @@ -204,7 +205,7 @@ void bdb_open_databases(void) { exit(CTDLEXIT_DB); } dbenv->set_errpfx(dbenv, "citserver"); - dbenv->set_paniccall(dbenv, dbpanic); + dbenv->set_paniccall(dbenv, bdb_dbpanic); dbenv->set_errcall(dbenv, bdb_verbose_err); dbenv->set_msgcall(dbenv, bdb_verbose_log); dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1); @@ -429,10 +430,10 @@ int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) return ret; } else { - bailIfCursor(TSD->cursors, "attempt to write during r/o cursor"); + bdb_bailIfCursor(TSD->cursors, "attempt to write during r/o cursor"); retry: - txbegin(&tid); + bdb_txbegin(&tid); if ((ret = dbp[cdb]->put(dbp[cdb], // db tid, // transaction ID @@ -440,7 +441,7 @@ int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) &ddata, // data 0))) { // flags if (ret == DB_LOCK_DEADLOCK) { - txabort(tid); + bdb_txabort(tid); goto retry; } else { @@ -449,7 +450,7 @@ int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) } } else { - txcommit(tid); + bdb_txcommit(tid); if (compressing) { free(compressed_data); } @@ -480,14 +481,14 @@ int bdb_delete(int cdb, void *key, int keylen) { } } else { - bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor"); + bdb_bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor"); retry: - txbegin(&tid); + bdb_txbegin(&tid); if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0)) && ret != DB_NOTFOUND) { if (ret == DB_LOCK_DEADLOCK) { - txabort(tid); + bdb_txabort(tid); goto retry; } else { @@ -496,14 +497,14 @@ int bdb_delete(int cdb, void *key, int keylen) { } } else { - txcommit(tid); + bdb_txcommit(tid); } } return ret; } -static DBC *localcursor(int cdb) { +static DBC *bdb_localcursor(int cdb) { int ret; DBC *curs; @@ -515,7 +516,7 @@ static DBC *localcursor(int cdb) { } if (ret) { - syslog(LOG_ERR, "bdb: localcursor: %s", db_strerror(ret)); + syslog(LOG_ERR, "bdb: bdb_localcursor: %s", db_strerror(ret)); bdb_abort(); } @@ -551,9 +552,9 @@ struct cdbdata *bdb_fetch(int cdb, const void *key, int keylen) { do { memset(&dret, 0, sizeof(DBT)); dret.flags = DB_DBT_MALLOC; - curs = localcursor(cdb); + curs = bdb_localcursor(cdb); ret = curs->c_get(curs, &dkey, &dret, DB_SET); - cclose(curs); + bdb_cclose(curs); } while (ret == DB_LOCK_DEADLOCK); } @@ -596,7 +597,7 @@ void bdb_free(struct cdbdata *cdb) { void bdb_close_cursor(int cdb) { if (TSD->cursors[cdb] != NULL) { - cclose(TSD->cursors[cdb]); + bdb_cclose(TSD->cursors[cdb]); } TSD->cursors[cdb] = NULL; @@ -612,7 +613,7 @@ void bdb_rewind(int cdb) { if (TSD->cursors[cdb] != NULL) { syslog(LOG_ERR, "bdb: bdb_rewind: must close cursor on database %d before reopening", cdb); bdb_abort(); - // cclose(TSD->cursors[cdb]); + // bdb_cclose(TSD->cursors[cdb]); } // Now initialize the cursor @@ -658,14 +659,14 @@ struct cdbdata *bdb_next_item(int cdb) { // Transaction-based stuff. I'm writing this as I bake cookies... void bdb_begin_transaction(void) { - bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor"); + bdb_bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor"); if (TSD->tid != NULL) { syslog(LOG_ERR, "bdb: bdb_begin_transaction: ERROR: nested transaction"); bdb_abort(); } - txbegin(&TSD->tid); + bdb_txbegin(&TSD->tid); } @@ -675,17 +676,17 @@ void bdb_end_transaction(void) { for (i = 0; i < MAXCDB; i++) { if (TSD->cursors[i] != NULL) { syslog(LOG_WARNING, "bdb: bdb_end_transaction: WARNING: cursor %d still open at transaction end", i); - cclose(TSD->cursors[i]); + bdb_cclose(TSD->cursors[i]); TSD->cursors[i] = NULL; } } if (TSD->tid == NULL) { - syslog(LOG_ERR, "bdb: bdb_end_transaction: ERROR: txcommit(NULL) !!"); + syslog(LOG_ERR, "bdb: bdb_end_transaction: ERROR: bdb_txcommit(NULL) !!"); bdb_abort(); } else { - txcommit(TSD->tid); + bdb_txcommit(TSD->tid); } TSD->tid = NULL; @@ -702,7 +703,7 @@ void bdb_trunc(int cdb) { bdb_abort(); } else { - bailIfCursor(TSD->cursors, "attempt to write during r/o cursor"); + bdb_bailIfCursor(TSD->cursors, "attempt to write during r/o cursor"); retry: -- 2.39.2