]> code.citadel.org Git - citadel.git/blobdiff - citadel/database_sleepycat.c
getuserbynumber() now uses a proper indexed database
[citadel.git] / citadel / database_sleepycat.c
index 7197009ea7e3b94db31e2ff4a9f1156b9ad55f1b..f6ac91179856ca95c71977ee23f5e085323efa2f 100644 (file)
@@ -43,6 +43,7 @@
 #endif
 
 
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -51,6 +52,7 @@
 #include "sysdep_decls.h"
 #include "threads.h"
 #include "config.h"
+#include "control.h"
 
 #include "ctdl_module.h"
 
@@ -143,7 +145,7 @@ static void bailIfCursor(DBC ** cursors, const char *msg)
        for (i = 0; i < MAXCDB; i++)
                if (cursors[i] != NULL) {
                        CtdlLogPrintf(CTDL_EMERG,
-                               "cdb_*: cursor still in progress on cdb %d: %s\n",
+                               "cdb_*: cursor still in progress on cdb %02x: %s\n",
                                i, msg);
                        abort();
                }
@@ -268,11 +270,30 @@ void open_databases(void)
        int i;
        char dbfilename[SIZ];
        u_int32_t flags = 0;
+       int dbversion_major, dbversion_minor, dbversion_patch;
+       int current_dbversion = 0;
 
        CtdlLogPrintf(CTDL_DEBUG, "cdb_*: open_databases() starting\n");
        CtdlLogPrintf(CTDL_DEBUG, "Compiled db: %s\n", DB_VERSION_STRING);
        CtdlLogPrintf(CTDL_INFO, "  Linked db: %s\n",
-               db_version(NULL, NULL, NULL));
+               db_version(&dbversion_major, &dbversion_minor, &dbversion_patch));
+
+       current_dbversion = (dbversion_major * 1000000) + (dbversion_minor * 1000) + dbversion_patch;
+
+       CtdlLogPrintf(CTDL_DEBUG, "Calculated dbversion: %d\n", current_dbversion);
+       CtdlLogPrintf(CTDL_DEBUG, "  Previous dbversion: %d\n", CitControl.MMdbversion);
+
+       if (CitControl.MMdbversion > current_dbversion) {
+               CtdlLogPrintf(CTDL_EMERG, "You are attempting to run the Citadel server using a version\n"
+                                       "of Berkeley DB that is older than that which last created or\n"
+                                       "updated the database.  Because this would probably cause data\n"
+                                       "corruption or loss, the server is aborting execution now.\n");
+               exit(CTDLEXIT_DB);
+       }
+
+       CitControl.MMdbversion = current_dbversion;
+       put_control();
+
 #ifdef HAVE_ZLIB
        CtdlLogPrintf(CTDL_INFO, "Linked zlib: %s\n", zlibVersion());
 #endif
@@ -370,7 +391,7 @@ void open_databases(void)
                                   DB_CREATE | DB_AUTO_COMMIT | DB_THREAD,
                                   0600);
                if (ret) {
-                       CtdlLogPrintf(CTDL_EMERG, "db_open[%d]: %s\n", i,
+                       CtdlLogPrintf(CTDL_EMERG, "db_open[%02x]: %s\n", i,
                                db_strerror(ret));
                        exit(CTDLEXIT_DB);
                }
@@ -433,7 +454,7 @@ void close_databases(void)
 
        /* close the tables */
        for (a = 0; a < MAXCDB; ++a) {
-               CtdlLogPrintf(CTDL_INFO, "Closing database %d\n", a);
+               CtdlLogPrintf(CTDL_INFO, "Closing database %02x\n", a);
                ret = dbp[a]->close(dbp[a], 0);
                if (ret) {
                        CtdlLogPrintf(CTDL_EMERG,