1 // This is a data store backend for the Citadel server which uses Berkeley DB.
3 // Copyright (c) 1987-2023 by the citadel.org team
5 // This program is open source software. Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
8 // Citadel will checkpoint the db at the end of every session, but only if
9 // the specified number of kilobytes has been written, or if the specified
10 // number of minutes has passed, since the last checkpoint.
11 #define MAX_CHECKPOINT_KBYTES 256
12 #define MAX_CHECKPOINT_MINUTES 15
14 #include "../../sysdep.h"
20 #include <libcitadel.h>
21 #include "../../citserver.h"
22 #include "../../config.h"
23 #include "berkeley_db.h"
25 #if DB_VERSION_MAJOR < 18
26 #error Citadel requires Berkeley DB v18.0 or newer. Please upgrade.
29 // Globals (these are used across multiple functions in *this* module, but not elsewhere)
30 static DB *dbp[MAXCDB]; // One DB handle for each Citadel database
31 static DB_ENV *dbenv; // The DB environment (global)
34 // Thread-Specific-Storage items for this backend
36 DB_TXN *tid; // Transaction handle
37 DBC *cursors[MAXCDB]; // Cursors, for traversals...
41 pthread_key_t bdb_thread_key;
45 // Return a pointer to our thread-specific (not session-specific) data.
46 struct thread_tsd *bdb_tsd(void) {
48 struct thread_tsd *c = (struct thread_tsd *) pthread_getspecific(bdb_thread_key) ;
53 // If there's no TSD for this thread, it must be a new thread. Create our TSD region.
54 c = (struct thread_tsd *) malloc(sizeof(struct thread_tsd));
55 memset(c, 0, sizeof(struct thread_tsd));
56 pthread_setspecific(bdb_thread_key, (const void *) c);
61 // Called by other functions in this module to GTFO quickly if we need to. Not part of the backend API.
62 void bdb_abort(void) {
63 syslog(LOG_DEBUG, "bdb: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
64 getuid(), getgid(), geteuid(), getegid()
66 raise(SIGABRT); // This will exit in a way that can produce a core dump if needed.
67 exit(CTDLEXIT_DB); // Exit if the signal failed to end the program.
71 // Verbose logging callback for Berkeley DB. Not part of the backend API.
72 void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) {
73 if (!IsEmptyStr(msg)) {
74 syslog(LOG_DEBUG, "bdb: %s %s", msg, foo);
79 // Verbose error logging callback for Berkeley DB. Not part of the backend API.
80 void bdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) {
81 syslog(LOG_ERR, "bdb: %s", msg);
85 // Wrapper for txn_abort() that logs/aborts on error. Not part of the backend API.
86 static void bdb_txabort(DB_TXN *tid) {
89 ret = tid->abort(tid);
92 syslog(LOG_ERR, "bdb: txn_abort: %s", db_strerror(ret));
98 // Wrapper for txn_commit() that logs/aborts on error. Not part of the backend API.
99 static void bdb_txcommit(DB_TXN *tid) {
102 ret = tid->commit(tid, 0);
105 syslog(LOG_ERR, "bdb: txn_commit: %s", db_strerror(ret));
111 // Wrapper for txn_begin() that logs/aborts on error. Not part of the backend API.
112 static void bdb_txbegin(DB_TXN **tid) {
115 ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
118 syslog(LOG_ERR, "bdb: txn_begin: %s", db_strerror(ret));
124 // Panic callback for Berkeley DB. Not part of the backend API.
125 static void bdb_dbpanic(DB_ENV *env, int errval) {
126 syslog(LOG_ERR, "bdb: PANIC: %s", db_strerror(errval));
131 // Close a cursor -- not part of the backend API.
132 static void bdb_cclose(DBC *cursor) {
135 if ((ret = cursor->c_close(cursor))) {
136 syslog(LOG_ERR, "bdb: c_close: %s", db_strerror(ret));
142 // Convenience function to abort if a cursor is still open when we didn't expect it to be.
143 // This is not part of the backend API.
144 static void bdb_bailIfCursor(DBC **cursors, const char *msg) {
147 for (i = 0; i < MAXCDB; i++)
148 if (cursors[i] != NULL) {
149 syslog(LOG_ERR, "bdb: cursor still in progress on cdb %02x: %s", i, msg);
155 void bdb_check_handles(void) {
156 bdb_bailIfCursor(TSD->cursors, "in check_handles");
158 if (TSD->tid != NULL) {
159 syslog(LOG_ERR, "bdb: transaction still in progress!");
165 // Request a checkpoint of the database. Called once per minute by the thread manager.
166 void bdb_checkpoint(void) {
169 syslog(LOG_DEBUG, "bdb: -- checkpoint --");
170 ret = dbenv->txn_checkpoint(dbenv, MAX_CHECKPOINT_KBYTES, MAX_CHECKPOINT_MINUTES, 0);
173 syslog(LOG_ERR, "bdb: bdb_checkpoint() txn_checkpoint: %s", db_strerror(ret));
177 // After a successful checkpoint, we can cull the unused logs
178 if (CtdlGetConfigInt("c_auto_cull")) {
179 ret = dbenv->log_set_config(dbenv, DB_LOG_AUTO_REMOVE, 1);
182 ret = dbenv->log_set_config(dbenv, DB_LOG_AUTO_REMOVE, 0);
187 // Open the various databases we'll be using. Any database which
188 // does not exist should be created. Note that we don't need a
189 // critical section here, because there aren't any active threads
190 // manipulating the database yet.
191 void bdb_open_databases(void) {
196 int dbversion_major, dbversion_minor, dbversion_patch;
198 syslog(LOG_DEBUG, "bdb: bdb_open_databases() starting");
199 syslog(LOG_DEBUG, "bdb: Linked zlib: %s", zlibVersion());
200 syslog(LOG_DEBUG, "bdb: Compiled libdb: %s", DB_VERSION_STRING);
201 syslog(LOG_DEBUG, "bdb: Linked libdb: %s", db_version(&dbversion_major, &dbversion_minor, &dbversion_patch));
203 // Create synthetic integer version numbers and compare them.
204 // Never allow citserver to run with a libdb older then the one with which it was compiled.
205 int compiled_db_version = ( (DB_VERSION_MAJOR * 1000000) + (DB_VERSION_MINOR * 1000) + (DB_VERSION_PATCH) );
206 int linked_db_version = ( (dbversion_major * 1000000) + (dbversion_minor * 1000) + (dbversion_patch) );
207 if (compiled_db_version > linked_db_version) {
208 syslog(LOG_ERR, "bdb: citserver is running with a version of libdb older than the one with which it was compiled.");
209 syslog(LOG_ERR, "bdb: This is an invalid configuration. citserver will now exit to prevent data loss.");
213 // Silently try to create the database subdirectory. If it's already there, no problem.
214 if ((mkdir(ctdl_db_dir, 0700) != 0) && (errno != EEXIST)) {
215 syslog(LOG_ERR, "bdb: database directory [%s] does not exist and could not be created: %m", ctdl_db_dir);
218 if (chmod(ctdl_db_dir, 0700) != 0) {
219 syslog(LOG_ERR, "bdb: unable to set database directory permissions [%s]: %m", ctdl_db_dir);
222 if (chown(ctdl_db_dir, CTDLUID, (-1)) != 0) {
223 syslog(LOG_ERR, "bdb: unable to set the owner for [%s]: %m", ctdl_db_dir);
226 syslog(LOG_DEBUG, "bdb: Setting up DB environment");
227 ret = db_env_create(&dbenv, 0);
229 syslog(LOG_ERR, "bdb: db_env_create: %s", db_strerror(ret));
230 syslog(LOG_ERR, "bdb: exit code %d", ret);
233 dbenv->set_errpfx(dbenv, "citserver");
234 dbenv->set_paniccall(dbenv, bdb_dbpanic);
235 dbenv->set_errcall(dbenv, bdb_verbose_err);
236 dbenv->set_msgcall(dbenv, bdb_verbose_log);
237 dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
238 dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
240 // We want to specify the shared memory buffer pool cachesize, but everything else is the default.
241 ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0);
243 syslog(LOG_ERR, "bdb: set_cachesize: %s", db_strerror(ret));
244 dbenv->close(dbenv, 0);
245 syslog(LOG_ERR, "bdb: exit code %d", ret);
249 if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT))) {
250 syslog(LOG_ERR, "bdb: set_lk_detect: %s", db_strerror(ret));
251 dbenv->close(dbenv, 0);
252 syslog(LOG_ERR, "bdb: exit code %d", ret);
256 flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD | DB_INIT_LOG;
257 syslog(LOG_DEBUG, "bdb: dbenv->open(dbenv, %s, %d, 0)", ctdl_db_dir, flags);
258 ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0); // try opening the database cleanly
259 if (ret == DB_RUNRECOVERY) {
260 syslog(LOG_ERR, "bdb: dbenv->open: %s", db_strerror(ret));
261 syslog(LOG_ERR, "bdb: attempting recovery...");
263 ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0); // try recovery
265 if (ret == DB_RUNRECOVERY) {
266 syslog(LOG_ERR, "bdb: dbenv->open: %s", db_strerror(ret));
267 syslog(LOG_ERR, "bdb: attempting catastrophic recovery...");
268 flags &= ~DB_RECOVER;
269 flags |= DB_RECOVER_FATAL;
270 ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0); // try catastrophic recovery
273 syslog(LOG_ERR, "bdb: dbenv->open: %s", db_strerror(ret));
274 dbenv->close(dbenv, 0);
275 syslog(LOG_ERR, "bdb: exit code %d", ret);
279 syslog(LOG_INFO, "bdb: mounting databases");
280 for (i = 0; i < MAXCDB; ++i) {
281 ret = db_create(&dbp[i], dbenv, 0); // Create a database handle
283 syslog(LOG_ERR, "bdb: db_create: %s", db_strerror(ret));
284 syslog(LOG_ERR, "bdb: exit code %d", ret);
288 snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i); // table names by number
289 ret = dbp[i]->open(dbp[i], NULL, dbfilename, NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT | DB_THREAD, 0600);
291 syslog(LOG_ERR, "bdb: db_open[%02x]: %s", i, db_strerror(ret));
293 syslog(LOG_ERR, "bdb: You may need to tune your database; please check http://www.citadel.org for more information.");
295 syslog(LOG_ERR, "bdb: exit code %d", ret);
302 // Make sure we own all the files, because in a few milliseconds we're going to drop root privs.
303 void bdb_chmod_data(void) {
306 char filename[PATH_MAX];
308 dp = opendir(ctdl_db_dir);
310 while (d = readdir(dp), d != NULL) {
311 if (d->d_name[0] != '.') {
312 snprintf(filename, sizeof filename, "%s/%s", ctdl_db_dir, d->d_name);
313 syslog(LOG_DEBUG, "bdb: chmod(%s, 0600) returned %d", filename, chmod(filename, 0600));
314 syslog(LOG_DEBUG, "bdb: chown(%s, CTDLUID, -1) returned %d", filename, chown(filename, CTDLUID, (-1)));
322 // Close all of the db database files we've opened. This can be done in a loop, since it's just a bunch of closes.
323 void bdb_close_databases(void) {
327 static int closing = 0;
328 while (closing == 1) {
329 syslog(LOG_INFO, "bdb: already closing");
333 syslog(LOG_INFO, "bdb: performing final checkpoint");
334 if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
335 syslog(LOG_ERR, "bdb: txn_checkpoint: %s", db_strerror(ret));
338 syslog(LOG_INFO, "bdb: flushing the database logs");
339 if ((ret = dbenv->log_flush(dbenv, NULL))) {
340 syslog(LOG_ERR, "bdb: log_flush: %s", db_strerror(ret));
344 syslog(LOG_INFO, "bdb: closing databases");
345 for (i = 0; i < MAXCDB; ++i) {
346 syslog(LOG_INFO, "bdb: closing database %02x", i);
347 ret = dbp[i]->close(dbp[i], 0);
349 syslog(LOG_ERR, "bdb: db_close: %s", db_strerror(ret));
354 ret = dbenv->close(dbenv, DB_FORCESYNC);
356 syslog(LOG_ERR, "bdb: DBENV->close: %s", db_strerror(ret));
361 // Decompress a database item if it was compressed on disk
362 void bdb_decompress_if_necessary(struct cdbdata *cdb) {
363 static int magic = COMPRESS_MAGIC;
365 if ((cdb == NULL) || (cdb->ptr == NULL) || (cdb->len < sizeof(magic)) || (memcmp(cdb->ptr, &magic, sizeof(magic)))) {
369 // At this point we know we're looking at a compressed item.
371 struct CtdlCompressHeader zheader;
372 char *uncompressed_data;
373 char *compressed_data;
374 uLongf destLen, sourceLen;
377 memset(&zheader, 0, sizeof(struct CtdlCompressHeader));
378 cplen = sizeof(struct CtdlCompressHeader);
379 if (sizeof(struct CtdlCompressHeader) > cdb->len) {
382 memcpy(&zheader, cdb->ptr, cplen);
384 compressed_data = cdb->ptr;
385 compressed_data += sizeof(struct CtdlCompressHeader);
387 sourceLen = (uLongf) zheader.compressed_len;
388 destLen = (uLongf) zheader.uncompressed_len;
389 uncompressed_data = malloc(zheader.uncompressed_len);
391 if (uncompress((Bytef *) uncompressed_data,
392 (uLongf *) &destLen, (const Bytef *) compressed_data, (uLong) sourceLen) != Z_OK) {
393 syslog(LOG_ERR, "bdb: uncompress() error");
398 cdb->len = (size_t) destLen;
399 cdb->ptr = uncompressed_data;
403 // Store a piece of data. Returns 0 if the operation was successful. If a
404 // key already exists it should be overwritten.
405 int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) {
410 struct CtdlCompressHeader zheader;
411 char *compressed_data = NULL;
413 size_t buffer_len = 0;
416 memset(&dkey, 0, sizeof(DBT));
417 memset(&ddata, 0, sizeof(DBT));
419 dkey.data = (void *) ckey;
420 ddata.size = cdatalen;
423 // "visit" records are numerous and have big, mostly-empty string buffers in them.
424 // If we compress these we can get them down to 1% of their size most of the time.
425 if (cdb == CDB_VISIT) {
427 zheader.magic = COMPRESS_MAGIC;
428 zheader.uncompressed_len = cdatalen;
429 buffer_len = ((cdatalen * 101) / 100) + 100 + sizeof(struct CtdlCompressHeader);
430 destLen = (uLongf) buffer_len;
431 compressed_data = malloc(buffer_len);
432 if (compress2((Bytef *) (compressed_data + sizeof(struct CtdlCompressHeader)), &destLen, (Bytef *) cdata, (uLongf) cdatalen, 1) != Z_OK) {
433 syslog(LOG_ERR, "bdb: compress2() error");
436 zheader.compressed_len = (size_t) destLen;
437 memcpy(compressed_data, &zheader, sizeof(struct CtdlCompressHeader));
438 ddata.size = (size_t) (sizeof(struct CtdlCompressHeader) + zheader.compressed_len);
439 ddata.data = compressed_data;
442 if (TSD->tid != NULL) {
443 ret = dbp[cdb]->put(dbp[cdb], // db
444 TSD->tid, // transaction ID
450 syslog(LOG_ERR, "bdb: bdb_store(%d): %s", cdb, db_strerror(ret));
454 free(compressed_data);
459 bdb_bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
464 if ((ret = dbp[cdb]->put(dbp[cdb], // db
465 tid, // transaction ID
469 if (ret == DB_LOCK_DEADLOCK) {
474 syslog(LOG_ERR, "bdb: bdb_store(%d): %s", cdb, db_strerror(ret));
481 free(compressed_data);
490 // Delete a piece of data. Returns 0 if the operation was successful.
491 int bdb_delete(int cdb, void *key, int keylen) {
496 memset(&dkey, 0, sizeof dkey);
500 if (TSD->tid != NULL) {
501 ret = dbp[cdb]->del(dbp[cdb], TSD->tid, &dkey, 0);
503 syslog(LOG_ERR, "bdb: bdb_delete(%d): %s", cdb, db_strerror(ret));
504 if (ret != DB_NOTFOUND) {
510 bdb_bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor");
515 if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0)) && ret != DB_NOTFOUND) {
516 if (ret == DB_LOCK_DEADLOCK) {
521 syslog(LOG_ERR, "bdb: bdb_delete(%d): %s", cdb, db_strerror(ret));
533 static DBC *bdb_localcursor(int cdb) {
537 if (TSD->cursors[cdb] == NULL) {
538 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &curs, 0);
541 ret = TSD->cursors[cdb]->c_dup(TSD->cursors[cdb], &curs, DB_POSITION);
545 syslog(LOG_ERR, "bdb: bdb_localcursor: %s", db_strerror(ret));
553 // Fetch a piece of data. If not found, returns NULL. Otherwise, it returns
554 // a struct cdbdata which it is the caller's responsibility to free later on
555 // using the bdb_free() routine.
556 struct cdbdata *bdb_fetch(int cdb, const void *key, int keylen) {
558 if (keylen == 0) { // key length zero is impossible
562 struct cdbdata *tempcdb;
566 memset(&dkey, 0, sizeof(DBT));
568 dkey.data = (void *) key;
570 if (TSD->tid != NULL) {
571 memset(&dret, 0, sizeof(DBT));
572 dret.flags = DB_DBT_MALLOC;
573 ret = dbp[cdb]->get(dbp[cdb], TSD->tid, &dkey, &dret, 0);
579 memset(&dret, 0, sizeof(DBT));
580 dret.flags = DB_DBT_MALLOC;
581 curs = bdb_localcursor(cdb);
582 ret = curs->c_get(curs, &dkey, &dret, DB_SET);
584 } while (ret == DB_LOCK_DEADLOCK);
587 if ((ret != 0) && (ret != DB_NOTFOUND)) {
588 syslog(LOG_ERR, "bdb: bdb_fetch(%d): %s", cdb, db_strerror(ret));
596 tempcdb = (struct cdbdata *) malloc(sizeof(struct cdbdata));
597 if (tempcdb == NULL) {
598 syslog(LOG_ERR, "bdb: bdb_fetch() cannot allocate memory for tempcdb: %m");
602 tempcdb->len = dret.size;
603 tempcdb->ptr = dret.data;
604 bdb_decompress_if_necessary(tempcdb);
610 // Free a cdbdata item.
612 // Note that we only free the 'ptr' portion if it is not NULL. This allows
613 // other code to assume ownership of that memory simply by storing the
614 // pointer elsewhere and then setting 'ptr' to NULL. bdb_free() will then
616 void bdb_free(struct cdbdata *cdb) {
624 void bdb_close_cursor(int cdb) {
625 if (TSD->cursors[cdb] != NULL) {
626 bdb_cclose(TSD->cursors[cdb]);
629 TSD->cursors[cdb] = NULL;
633 // Prepare for a sequential search of an entire database.
634 // (There is guaranteed to be no more than one traversal in
635 // progress per thread at any given time.)
636 void bdb_rewind(int cdb) {
639 if (TSD->cursors[cdb] != NULL) {
640 syslog(LOG_ERR, "bdb: bdb_rewind: must close cursor on database %d before reopening", cdb);
642 // bdb_cclose(TSD->cursors[cdb]);
645 // Now initialize the cursor
646 ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &TSD->cursors[cdb], 0);
648 syslog(LOG_ERR, "bdb: bdb_rewind: db_cursor: %s", db_strerror(ret));
654 // Fetch the next item in a sequential search. Returns a pointer to a
655 // cdbdata structure, or NULL if we've hit the end.
656 struct cdbdata *bdb_next_item(int cdb) {
658 struct cdbdata *cdbret;
661 // Initialize the key/data pair so the flags aren't set.
662 memset(&key, 0, sizeof(key));
663 memset(&data, 0, sizeof(data));
664 data.flags = DB_DBT_MALLOC;
666 ret = TSD->cursors[cdb]->c_get(TSD->cursors[cdb], &key, &data, DB_NEXT);
669 if (ret != DB_NOTFOUND) {
670 syslog(LOG_ERR, "bdb: bdb_next_item(%d): %s", cdb, db_strerror(ret));
673 bdb_close_cursor(cdb);
674 return NULL; // presumably, end of file
677 cdbret = (struct cdbdata *) malloc(sizeof(struct cdbdata));
678 cdbret->len = data.size;
679 cdbret->ptr = data.data;
680 bdb_decompress_if_necessary(cdbret);
686 // Transaction-based stuff. I'm writing this as I bake cookies...
687 void bdb_begin_transaction(void) {
688 bdb_bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
690 if (TSD->tid != NULL) {
691 syslog(LOG_ERR, "bdb: bdb_begin_transaction: ERROR: nested transaction");
695 bdb_txbegin(&TSD->tid);
699 void bdb_end_transaction(void) {
702 for (i = 0; i < MAXCDB; i++) {
703 if (TSD->cursors[i] != NULL) {
704 syslog(LOG_WARNING, "bdb: bdb_end_transaction: WARNING: cursor %d still open at transaction end", i);
705 bdb_cclose(TSD->cursors[i]);
706 TSD->cursors[i] = NULL;
710 if (TSD->tid == NULL) {
711 syslog(LOG_ERR, "bdb: bdb_end_transaction: ERROR: bdb_txcommit(NULL) !!");
715 bdb_txcommit(TSD->tid);
722 // Truncate (delete every record)
723 void bdb_trunc(int cdb) {
727 if (TSD->tid != NULL) {
728 syslog(LOG_ERR, "bdb: bdb_trunc must not be called in a transaction.");
732 bdb_bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
736 if ((ret = dbp[cdb]->truncate(dbp[cdb], // db
737 NULL, // transaction ID
738 &count, // #rows deleted
740 if (ret == DB_LOCK_DEADLOCK) {
744 syslog(LOG_ERR, "bdb: bdb_truncate(%d): %s", cdb, db_strerror(ret));
746 syslog(LOG_ERR, "bdb: You may need to tune your database; please read http://www.citadel.org for more information.");
755 // compact (defragment) the database, possibly returning space back to the underlying filesystem
756 void bdb_compact(void) {
760 syslog(LOG_DEBUG, "bdb: bdb_compact() started");
761 for (i = 0; i < MAXCDB; i++) {
762 syslog(LOG_DEBUG, "bdb: compacting database %d", i);
763 ret = dbp[i]->compact(dbp[i], NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL);
765 syslog(LOG_ERR, "bdb: compact: %s", db_strerror(ret));
768 syslog(LOG_DEBUG, "bdb: bdb_compact() finished");
772 // Calling this function activates the Berkeley DB back end.
773 void bdb_init_backend(void) {
774 cdb_compact = bdb_compact;
775 cdb_checkpoint = bdb_checkpoint;
776 cdb_rewind = bdb_rewind;
777 cdb_fetch = bdb_fetch;
778 cdb_open_databases = bdb_open_databases;
779 cdb_close_databases = bdb_close_databases;
780 cdb_store = bdb_store;
781 cdb_delete = bdb_delete;
783 cdb_next_item = bdb_next_item;
784 cdb_close_cursor = bdb_close_cursor;
785 cdb_begin_transaction = bdb_begin_transaction;
786 cdb_end_transaction = bdb_end_transaction;
787 cdb_check_handles = bdb_check_handles;
788 cdb_trunc = bdb_trunc;
789 cdb_chmod_data = bdb_chmod_data;
791 if (pthread_key_create(&bdb_thread_key, NULL) != 0) { // TSD key for this module
792 syslog(LOG_ERR, "pthread_key_create() : %m");
793 exit(CTDLEXIT_THREAD);
796 syslog(LOG_INFO, "db: initialized Berkeley DB backend");