From: Dave West Date: Mon, 16 Jun 2008 13:06:14 +0000 (+0000) Subject: Implimented a new way to check the control record at startup. X-Git-Tag: v7.86~2148 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=983b1699a778b7f0db81406157f764fcfe87f09c Implimented a new way to check the control record at startup. We now have a check_control() that is called after the DB's are opened --- diff --git a/citadel/control.c b/citadel/control.c index 74070e4aa..989e36c9f 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -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 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 */ diff --git a/citadel/control.h b/citadel/control.h index ac75776e8..d4c0b79f6 100644 --- a/citadel/control.h +++ b/citadel/control.h @@ -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); diff --git a/citadel/server_main.c b/citadel/server_main.c index ea03a202c..0503221da 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -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 */