ctdldump: use the backend API instead of BDB calls
[citadel.git] / citadel / server / backends / berkeley_db / berkeley_db.c
index 2a8e2f14a819635ad0946e4135ab6c124808e5e3..e2c102cf6230381a42fcc3230c434c553b7dd267 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <zlib.h>
 #include <db.h>
+#include <assert.h>
 #include <libcitadel.h>
 #include "../../citserver.h"
 #include "../../config.h"
@@ -45,6 +46,7 @@ pthread_key_t bdb_thread_key;
 
 // Some functions in this backend need to store some per-thread data.
 // This returns the pointer to the current thread's per-thread data block, creating it if necessary.
+// (This will also work in a non-threaded program; it will return the same pointer every time.)
 struct bdb_tsd *bdb_get_tsd(void) {
 
         struct bdb_tsd *c = (struct bdb_tsd *) pthread_getspecific(bdb_thread_key) ;
@@ -264,8 +266,8 @@ void bdb_open_databases(void) {
                exit(CTDLEXIT_DB);
        }
 
-       syslog(LOG_INFO, "bdb: mounting databases");
        for (i = 0; i < MAXCDB; ++i) {
+               syslog(LOG_INFO, "bdb: mounting database %02x", i);
                ret = db_create(&bdb_table[i], bdb_env, 0);                             // Create a database handle
                if (ret) {
                        syslog(LOG_ERR, "bdb: db_create: %s", db_strerror(ret));
@@ -607,6 +609,7 @@ struct cdbkeyval bdb_next_item(int cdb) {
        TSD->dbkey[cdb].flags = DB_DBT_MALLOC;
        TSD->dbdata[cdb].flags = DB_DBT_MALLOC;
 
+       assert(TSD->cursors[cdb] != NULL);
        ret = TSD->cursors[cdb]->c_get(TSD->cursors[cdb], &TSD->dbkey[cdb], &TSD->dbdata[cdb], DB_NEXT);
 
        if (ret) {