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 27d96df999 )
This commit is contained in:
rofl0r 2020-01-15 17:02:22 +00:00
parent 5dd514af93
commit 2e02dce0c3

View File

@ -48,11 +48,17 @@
* Global Structures * Global Structures
*/ */
struct config_s *config; struct config_s *config;
static struct config_s config_main; static struct config_s configs[2];
static struct config_s config_defaults;
static const char* config_file; static const char* config_file;
unsigned int received_sighup = FALSE; /* boolean */ 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 * Handle a signal
*/ */
@ -247,16 +253,17 @@ change_user (const char *program)
int reload_config (int reload_logging) int reload_config (int reload_logging)
{ {
int ret; int ret;
struct config_s *c_next = get_next_config();
if (reload_logging) shutdown_logging (); if (reload_logging) shutdown_logging ();
ret = reload_config_file (config_file, &config_main); ret = reload_config_file (config_file, c_next);
if (ret != 0) { if (ret != 0) {
goto done; goto done;
} }
config = &config_main; config = c_next;
if (reload_logging) ret = setup_logging (); if (reload_logging) ret = setup_logging ();