sanity check diagnostic mode
authorArt Cancro <ajc@citadel.org>
Wed, 8 Aug 2018 14:24:53 +0000 (10:24 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 8 Aug 2018 14:24:53 +0000 (10:24 -0400)
citadel/control.c
citadel/server.h
citadel/server_main.c

index ff4c0ea80224f4fc003738b5af5df956f49b41f4..d2e99148a94e3b2895504de2c4cefbaf61c59ac5 100644 (file)
@@ -53,7 +53,9 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data)
        
        if (qrbuf->QRnumber > CtdlGetConfigLong("MMnextroom")) {
                syslog(LOG_DEBUG, "control: fixing MMnextroom %ld > %ld", qrbuf->QRnumber, CtdlGetConfigLong("MMnextroom"));
-               CtdlSetConfigLong("MMnextroom", qrbuf->QRnumber);
+               if (!sanity_diag_mode) {
+                       CtdlSetConfigLong("MMnextroom", qrbuf->QRnumber);
+               }
        }
                
        CtdlGetRoom(&room, qrbuf->QRname);
@@ -71,7 +73,9 @@ void control_find_highest(struct ctdlroom *qrbuf, void *data)
                for (c=0; c<num_msgs; c++) {
                        if (msglist[c] > CtdlGetConfigLong("MMhighest")) {
                                syslog(LOG_DEBUG, "control: fixing MMhighest %ld > %ld", msglist[c], CtdlGetConfigLong("MMhighest"));
-                               CtdlSetConfigLong("MMhighest", msglist[c]);
+                               if (!sanity_diag_mode) {
+                                       CtdlSetConfigLong("MMhighest", msglist[c]);
+                               }
                        }
                }
        }
@@ -87,7 +91,9 @@ void control_find_user(struct ctdluser *EachUser, void *out_data)
 {
        if (EachUser->usernum > CtdlGetConfigLong("MMnextuser")) {
                syslog(LOG_DEBUG, "control: fixing MMnextuser %ld > %ld", EachUser->usernum, CtdlGetConfigLong("MMnextuser"));
-               CtdlSetConfigLong("MMnextuser", EachUser->usernum);
+               if (!sanity_diag_mode) {
+                       CtdlSetConfigLong("MMnextuser", EachUser->usernum);
+               }
        }
 }
 
@@ -134,6 +140,10 @@ void check_control(void)
        syslog(LOG_INFO, "control: sanity checking the recorded highest user number");
        ForEachUser(control_find_user, NULL);
        syslog(LOG_INFO, "control: sanity checks complete");
+       if (sanity_diag_mode) {
+               syslog(LOG_INFO, "control: sanity check diagnostic mode is active - exiting now");
+               abort();
+       }
 }
 
 
index ec821d91b941db2c7121a73dccc76c6a5d83c211..837e8b252291d3f8be433412f49095fca9dca155 100644 (file)
@@ -118,6 +118,7 @@ enum {
 
 extern int ScheduledShutdown;
 extern uid_t ctdluid;
+extern int sanity_diag_mode;
 
 struct ExpressMessage {
        struct ExpressMessage *next;
index f24a69edcc55dc91bea02a9aadad455ce88cd972..8df0f343a249fd01525e917530ddd2530d1f1569 100644 (file)
@@ -33,6 +33,7 @@ uid_t ctdluid = 0;
 const char *CitadelServiceUDS="citadel-UDS";
 const char *CitadelServiceTCP="citadel-TCP";
 void go_threading(void);
+int sanity_diag_mode = 0;
 
 
 /*
@@ -93,7 +94,7 @@ int main(int argc, char **argv)
        InitializeMasterTSD();
 
        /* parse command-line arguments */
-       while ((a=getopt(argc, argv, "l:dh:x:t:B:Dru:")) != EOF) switch(a) {
+       while ((a=getopt(argc, argv, "l:dh:x:t:B:Dru:s")) != EOF) switch(a) {
 
                case 'l':
                        safestrncpy(facility, optarg, sizeof(facility));
@@ -154,6 +155,11 @@ int main(int argc, char **argv)
                        }
                        break;
 
+               /* -s tells the server to suppress fixing any discrepancies found during sanity checks, but exit after those checks complete */
+               case 's':
+                       sanity_diag_mode = 1;
+                       break;
+
                default:
                /* any other parameter makes it crash and burn */
                        fprintf(stderr, "citserver: usage: "