summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-12 23:38:36 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-12 23:38:36 +0100
commit6a2f7b87d4fb19f30f64ede4b18582eb366c8b7d (patch)
tree5400375fe286c33385762b741593d1e84ddffe11 /functions.c
parent3038e93b7e2e34296429a078b70205448c81e6cb (diff)
Allow reloading the configuration file at runtime using a BLABOUNCER command or by issuing the SIGHUP signal.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/functions.c b/functions.c
index 5dbeb0c..abffb0b 100644
--- a/functions.c
+++ b/functions.c
@@ -990,3 +990,64 @@ void cleanexit(SSL *server_ssl, struct client *clients, int sourcefd, struct irc
exit(0);
}
+
+// Re-read the configuration file, setting 'failuremsg' to a failure message on failure.
+// Returns 1 on success or 0 on failure.
+int rehash(struct settings *settings, char *failuremsg) {
+ // TODO - Try to share some/all of this code with the initial main() settings loading
+
+ // What is the auto replay mode?
+ char oldreplaymode[MAXDATASIZE];
+ strcpy(oldreplaymode, settings->replaymode);
+ if (!getconfstr("replaymode", settings->conffile, settings->replaymode)) {
+ strcpy(settings->replaymode, oldreplaymode);
+ strcpy(failuremsg, "error getting 'replaymode' from configuration file");
+ return 0;
+ } else {
+ if (strcmp(settings->replaymode, "none") && strcmp(settings->replaymode, "time") && strcmp(settings->replaymode, "lastspoke")) {
+ strcpy(settings->replaymode, oldreplaymode);
+ strcpy(failuremsg, "replaymode in configuration file must be one of \"none\", \"time\", or \"lastspoke\"");
+ return 0;
+ }
+ }
+
+ // How many seconds of replay log should automatically be replayed - TODO - Can we do error checking on this?
+ int oldreplayseconds = settings->replayseconds;
+ settings->replayseconds = getconfint("replayseconds", settings->conffile);
+ if (errno == ECONFINT) {
+ settings->replayseconds = oldreplayseconds;
+ strcpy(failuremsg, "error getting 'replayseconds' from configuration file");
+ return 0;
+ }
+
+ // Is logging enabled?
+ int oldlogging = settings->logging;
+ settings->logging = getconfint("logging", settings->conffile);
+ if (errno == ECONFINT) {
+ settings->logging = oldlogging;
+ strcpy(failuremsg, "error getting 'logging' from configuration file");
+ return 0;
+ }
+
+ // Is replay logging enabled?
+ int oldreplaylogging = settings->replaylogging;
+ settings->replaylogging = getconfint("replaylogging", settings->conffile);
+ if (errno == ECONFINT) {
+ settings->replaylogging = oldreplaylogging;
+ strcpy(failuremsg, "error getting 'replaylogging' from configuration file");
+ return 0;
+ }
+
+ // Is debugging enabled?
+ int olddebug = debug;
+ debug = getconfint("debug", settings->conffile);
+ if (errno == ECONFINT) {
+ debug = olddebug;
+ strcpy(failuremsg, "error getting 'debug' from configuration file");
+ return 0;
+ }
+
+ // All is good, no failure message, return 1.
+ failuremsg[0] = '\0';
+ return 1;
+}