From 47585659f82eec5dc6cedc9d6695e03ef34f019e Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 8 Aug 2018 10:24:53 -0400 Subject: [PATCH] sanity check diagnostic mode --- citadel/control.c | 16 +++++++++++++--- citadel/server.h | 1 + citadel/server_main.c | 8 +++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/citadel/control.c b/citadel/control.c index ff4c0ea80..d2e99148a 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -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 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(); + } } diff --git a/citadel/server.h b/citadel/server.h index ec821d91b..837e8b252 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -118,6 +118,7 @@ enum { extern int ScheduledShutdown; extern uid_t ctdluid; +extern int sanity_diag_mode; struct ExpressMessage { struct ExpressMessage *next; diff --git a/citadel/server_main.c b/citadel/server_main.c index f24a69edc..8df0f343a 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -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: " -- 2.30.2