From 6a2f7b87d4fb19f30f64ede4b18582eb366c8b7d Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Wed, 12 Jun 2019 23:38:36 +0100 Subject: Allow reloading the configuration file at runtime using a BLABOUNCER command or by issuing the SIGHUP signal. --- functions.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'functions.c') 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; +} -- cgit v1.2.3