From 2e02dce0c3de4a231f74b44c34647406de507768 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 15 Jan 2020 17:02:22 +0000 Subject: [PATCH] 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 ) --- src/main.c | 15 +++++++++++---- 1 file 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 ();