]> code.citadel.org Git - citadel.git/blobdiff - citadel/database.c
* Debugged all possible ways for a session to terminate; do them cleanly.
[citadel.git] / citadel / database.c
index e67c6d37373028ae0cf4c16862adc9b43fd80bf5..79ae1981344ccdd24c7b36b0f556370626e718ac 100644 (file)
@@ -15,6 +15,7 @@
  * conditions to occur.  (Deadlock is bad.  Eliminate.)
  */
 
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -22,8 +23,9 @@
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <pthread.h>
+#ifdef HAVE_GDBM_H
 #include <gdbm.h>
+#endif
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -37,7 +39,8 @@ GDBM_FILE gdbms[MAXCDB];
 
 /*
  * We also keep these around, for sequential searches... (one per 
- * session.  Maybe there's a better way?)
+ * session.  Maybe there's a better way?)    FIX ... there _is_ a better
+ * way.  We have TSD functions now; use them.
  */
 #define MAXKEYS 256
 datum dtkey[MAXKEYS];
@@ -50,6 +53,7 @@ datum dtkey[MAXKEYS];
 void defrag_databases(void) {
 
        /* defrag the message base */
+       lprintf(7, "Defragmenting message base\n");
        begin_critical_section(S_MSGMAIN);
        begin_critical_section(S_DATABASE);
        gdbm_reorganize(gdbms[CDB_MSGMAIN]);
@@ -57,6 +61,7 @@ void defrag_databases(void) {
        end_critical_section(S_MSGMAIN);
 
        /* defrag the user file, mailboxes, and user/room relationships */
+       lprintf(7, "Defragmenting user file\n");
        begin_critical_section(S_USERSUPP);
        begin_critical_section(S_DATABASE);
        gdbm_reorganize(gdbms[CDB_USERSUPP]);
@@ -65,6 +70,7 @@ void defrag_databases(void) {
        end_critical_section(S_USERSUPP);
 
        /* defrag the room files and message lists */
+       lprintf(7, "Defragmenting room files and message lists\n");
        begin_critical_section(S_QUICKROOM);
        begin_critical_section(S_DATABASE);
        gdbm_reorganize(gdbms[CDB_QUICKROOM]);
@@ -73,6 +79,7 @@ void defrag_databases(void) {
        end_critical_section(S_QUICKROOM);
 
        /* defrag the floor table */
+       lprintf(7, "Defragmenting floor table\n");
        begin_critical_section(S_FLOORTAB);
        begin_critical_section(S_DATABASE);
        gdbm_reorganize(gdbms[CDB_FLOORTAB]);
@@ -88,19 +95,27 @@ void defrag_databases(void) {
 void open_databases(void) {
        int a;
 
+       lprintf(7, "%s\n", gdbm_version);
+
        /*
         * Silently try to create the database subdirectory.  If it's
         * already there, no problem.
         */
        system("exec mkdir data 2>/dev/null");
 
+       /* a critical section is unnecessary, as this function is called before
+          any other threads are created. and it causes problems on BSDI.
+
        begin_critical_section(S_DATABASE);
 
+        */
+
        gdbms[CDB_MSGMAIN] = gdbm_open("data/msgmain.gdbm", 8192,
                GDBM_WRCREAT, 0600, NULL);
        if (gdbms[CDB_MSGMAIN] == NULL) {
                lprintf(2, "Cannot open msgmain: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        gdbms[CDB_USERSUPP] = gdbm_open("data/usersupp.gdbm", 0,
@@ -108,6 +123,7 @@ void open_databases(void) {
        if (gdbms[CDB_USERSUPP] == NULL) {
                lprintf(2, "Cannot open usersupp: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        gdbms[CDB_VISIT] = gdbm_open("data/visit.gdbm", 0,
@@ -115,6 +131,7 @@ void open_databases(void) {
        if (gdbms[CDB_VISIT] == NULL) {
                lprintf(2, "Cannot open visit file: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        gdbms[CDB_QUICKROOM] = gdbm_open("data/quickroom.gdbm", 0,
@@ -122,6 +139,7 @@ void open_databases(void) {
        if (gdbms[CDB_QUICKROOM] == NULL) {
                lprintf(2, "Cannot open quickroom: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        gdbms[CDB_FLOORTAB] = gdbm_open("data/floortab.gdbm", 0,
@@ -129,6 +147,7 @@ void open_databases(void) {
        if (gdbms[CDB_FLOORTAB] == NULL) {
                lprintf(2, "Cannot open floortab: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        gdbms[CDB_MSGLISTS] = gdbm_open("data/msglists.gdbm", 0,
@@ -136,6 +155,7 @@ void open_databases(void) {
        if (gdbms[CDB_MSGLISTS] == NULL) {
                lprintf(2, "Cannot open msglists: %s\n",
                        gdbm_strerror(gdbm_errno));
+               exit(1);
                }
 
        for (a=0; a<MAXKEYS; ++a) {
@@ -143,7 +163,9 @@ void open_databases(void) {
                dtkey[a].dptr = NULL;
                }
 
+       /*
        end_critical_section(S_DATABASE);
+        */
 
        }
 
@@ -155,11 +177,6 @@ void open_databases(void) {
 void close_databases(void) {
        int a;
 
-       /* Hmm... we should decide when would be a good time to defrag.
-        * Server shutdowns might be an opportune time.
-        */
-       defrag_databases();
-
        begin_critical_section(S_DATABASE);
        for (a=0; a<MAXCDB; ++a) {
                lprintf(7, "Closing database %d\n", a);