Implimented a new way to check the control record at startup.
authorDave West <davew@uncensored.citadel.org>
Mon, 16 Jun 2008 13:06:14 +0000 (13:06 +0000)
committerDave West <davew@uncensored.citadel.org>
Mon, 16 Jun 2008 13:06:14 +0000 (13:06 +0000)
We now have a check_control() that is called after the DB's are opened

citadel/control.c
citadel/control.h
citadel/server_main.c

index 74070e4aaaab4d7075e45cf2f9104ecfdee42d69..989e36c9f4564b54c37360a1f150387d14700ca2 100644 (file)
@@ -83,10 +83,14 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data)
        long *msglist;
        int num_msgs=0;
        int c;
-       
+       int room_fixed = 0;
+       int message_fixed = 0;
        
        if (qrbuf->QRnumber > CitControl.MMnextroom)
+       {
                CitControl.MMnextroom = qrbuf->QRnumber;
+               room_fixed = 1;
+       }
                
        getroom (&room, qrbuf->QRname);
        
@@ -104,10 +108,17 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data)
                for (c=0; c<num_msgs; c++)
                {
                        if (msglist[c] > CitControl.MMhighest)
+                       {
                                CitControl.MMhighest = msglist[c];
+                               message_fixed = 1;
+                       }
                }
        }
        cdb_free(cdbfr);
+       if (room_fixed)
+               CtdlLogPrintf(CTDL_INFO, "Control record checking....Fixed room counter\n");
+       if (message_fixed)
+               CtdlLogPrintf(CTDL_INFO, "Control record checking....Fixed message count\n");
        return;
 }
 
@@ -118,8 +129,15 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data)
  
 void control_find_user (struct ctdluser *EachUser, void *out_data)
 {
+       int user_fixed = 0;
+       
        if (EachUser->usernum > CitControl.MMnextuser)
+       {
                CitControl.MMnextuser = EachUser->usernum;
+               user_fixed = 1;
+       }
+       if(user_fixed)
+               CtdlLogPrintf(CTDL_INFO, "Control record checking....Fixed user count\n");
 }
 
 
@@ -154,9 +172,6 @@ void get_control(void)
                        lock_control();
                        fchown(fileno(control_fp), config.c_ctdluid, -1);
                        memset(&CitControl, 0, sizeof(struct CitControl));
-                       // Find highest room number and message number.
-                       // ForEachRoom(control_find_highest, NULL);
-                       // ForEachUser(control_find_user, NULL);
                        fwrite(&CitControl, sizeof(struct CitControl),
                               1, control_fp);
                        rewind(control_fp);
@@ -189,6 +204,21 @@ void put_control(void)
        }
 }
 
+
+/*
+ * check_control   -  check the control record has sensible values for message, user and room numbers
+ */
+void check_control(void)
+{
+       CtdlLogPrintf(CTDL_INFO, "Checking/re-building control record\n");
+       get_control();
+       // Find highest room number and message number.
+       ForEachRoom(control_find_highest, NULL);
+       ForEachUser(control_find_user, NULL);
+       put_control();
+}
+
+
 /**
  * release_control - close our fd on exit
  */
index ac75776e82253806934fd557378a68dfc4c38278..d4c0b79f6e3210c13ce9789352f8a5270601ccbf 100644 (file)
@@ -2,6 +2,7 @@
 void get_control (void);
 void put_control (void);
 void release_control(void);
+void check_control(void);
 long int get_new_message_number (void);
 long int get_new_user_number (void);
 long int get_new_room_number (void);
index ea03a202caf2dc8d28383f9cd15cfb8cfd2d1960..0503221dae6fdf5619361878d04fbcc197e1fb36 100644 (file)
@@ -249,6 +249,11 @@ int main(int argc, char **argv)
         */
        master_startup();
 
+       /*
+        * Check that the control record is correct and place sensible values if it isn't
+        */
+       check_control();
+       
        /*
         * Run any upgrade entry points
         */