summaryrefslogtreecommitdiffhomepage
path: root/src/main.c
diff options
context:
space:
mode:
authorrofl0r <rofl0r@users.noreply.github.com>2020-01-15 17:02:22 +0000
committerrofl0r <rofl0r@users.noreply.github.com>2020-01-15 17:03:47 +0000
commit2e02dce0c3de4a231f74b44c34647406de507768 (patch)
treefc09223f310531d5c9951989b519cb1619557c9a /src/main.c
parent5dd514af93675602cdece2b7b2112989b87d5d51 (diff)
conf: use 2 swappable conf slots, so old config can stay valid
... in case reloading of it after SIGHUP fails, the old config can continue working. (apart from the logging-related issue mentioned in 27d96df99900c5a62ab0fdf2a37565e78f256d6a )
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 8a3b6fa..2963957 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,11 +48,17 @@
* Global Structures
*/
struct config_s *config;
-static struct config_s config_main;
-static struct config_s config_defaults;
+static struct config_s configs[2];
static const char* config_file;
unsigned int received_sighup = FALSE; /* boolean */
+static struct config_s*
+get_next_config(void)
+{
+ if (config == &configs[0]) return &configs[1];
+ return &configs[0];
+}
+
/*
* Handle a signal
*/
@@ -247,16 +253,17 @@ change_user (const char *program)
int reload_config (int reload_logging)
{
int ret;
+ struct config_s *c_next = get_next_config();
if (reload_logging) shutdown_logging ();
- ret = reload_config_file (config_file, &config_main);
+ ret = reload_config_file (config_file, c_next);
if (ret != 0) {
goto done;
}
- config = &config_main;
+ config = c_next;
if (reload_logging) ret = setup_logging ();