We now have a check_control() that is called after the DB's are opened
long *msglist;
int num_msgs=0;
int c;
long *msglist;
int num_msgs=0;
int c;
+ int room_fixed = 0;
+ int message_fixed = 0;
if (qrbuf->QRnumber > CitControl.MMnextroom)
if (qrbuf->QRnumber > CitControl.MMnextroom)
CitControl.MMnextroom = qrbuf->QRnumber;
CitControl.MMnextroom = qrbuf->QRnumber;
getroom (&room, qrbuf->QRname);
getroom (&room, qrbuf->QRname);
for (c=0; c<num_msgs; c++)
{
if (msglist[c] > CitControl.MMhighest)
for (c=0; c<num_msgs; c++)
{
if (msglist[c] > CitControl.MMhighest)
CitControl.MMhighest = msglist[c];
CitControl.MMhighest = msglist[c];
+ 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");
void control_find_user (struct ctdluser *EachUser, void *out_data)
{
void control_find_user (struct ctdluser *EachUser, void *out_data)
{
if (EachUser->usernum > CitControl.MMnextuser)
if (EachUser->usernum > CitControl.MMnextuser)
CitControl.MMnextuser = EachUser->usernum;
CitControl.MMnextuser = EachUser->usernum;
+ user_fixed = 1;
+ }
+ if(user_fixed)
+ CtdlLogPrintf(CTDL_INFO, "Control record checking....Fixed user count\n");
lock_control();
fchown(fileno(control_fp), config.c_ctdluid, -1);
memset(&CitControl, 0, sizeof(struct CitControl));
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);
fwrite(&CitControl, sizeof(struct CitControl),
1, control_fp);
rewind(control_fp);
+
+/*
+ * 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
*/
/**
* release_control - close our fd on exit
*/
void get_control (void);
void put_control (void);
void release_control(void);
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);
long int get_new_message_number (void);
long int get_new_user_number (void);
long int get_new_room_number (void);
+ /*
+ * Check that the control record is correct and place sensible values if it isn't
+ */
+ check_control();
+
/*
* Run any upgrade entry points
*/
/*
* Run any upgrade entry points
*/