From: W.C.A. Wijngaards Date: Thu, 4 Jan 2024 09:30:59 +0000 (+0100) Subject: - fast-reload, reread config file from disk. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85127a43cc37c02f728485f696eb26d60ffd2bb2;p=thirdparty%2Funbound.git - fast-reload, reread config file from disk. --- diff --git a/daemon/daemon.c b/daemon/daemon.c index 9ee9a01a4..b229d2edb 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -896,6 +896,7 @@ daemon_delete(struct daemon* daemon) listen_desetup_locks(); free(daemon->chroot); free(daemon->pidfile); + free(daemon->cfgfile); free(daemon->env); #ifdef HAVE_SSL listen_sslctx_delete_ticket_keys(); diff --git a/daemon/daemon.h b/daemon/daemon.h index aeb68bd94..46cb5dbcc 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -152,6 +152,8 @@ struct daemon { struct fast_reload_thread* fast_reload_thread; /** the fast reload printq list */ struct fast_reload_printq* fast_reload_printq_list; + /** config file name */ + char* cfgfile; }; /** diff --git a/daemon/remote.c b/daemon/remote.c index 63ece5c59..1d6b18978 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -3657,6 +3657,57 @@ fr_output_printf(struct fast_reload_thread* fr, const char* format, ...) return ret; } +/** fast reload thread, read config */ +static int +fr_read_config(struct fast_reload_thread* fr, struct config_file** newcfg) +{ + /* Create new config structure. */ + *newcfg = config_create(); + if(!*newcfg) { + if(!fr_output_printf(fr, "config_create failed: out of memory\n")) + return 0; + fr_send_notification(fr, fast_reload_notification_printout); + return 0; + } + if(fr_poll_for_quit(fr)) + return 1; + + /* Read new config from file */ + if(!config_read(*newcfg, fr->worker->daemon->cfgfile, + fr->worker->daemon->chroot)) { + config_delete(*newcfg); + if(!fr_output_printf(fr, "config_read %s failed: %s\n", + fr->worker->daemon->cfgfile, strerror(errno))) + return 0; + fr_send_notification(fr, fast_reload_notification_printout); + return 0; + } + if(fr_poll_for_quit(fr)) + return 1; + if(!fr_output_printf(fr, "done read config file %s\n", + fr->worker->daemon->cfgfile)) + return 0; + fr_send_notification(fr, fast_reload_notification_printout); + + return 1; +} + +/** fast reload thread, load config */ +static int +fr_load_config(struct fast_reload_thread* fr) +{ + struct config_file* newcfg = NULL; + if(!fr_read_config(fr, &newcfg)) + return 0; + if(fr_poll_for_quit(fr)) { + config_delete(newcfg); + return 1; + } + + config_delete(newcfg); + return 1; +} + /** fast reload thread. the thread main function */ static void* fast_reload_thread_main(void* arg) { @@ -3675,6 +3726,11 @@ static void* fast_reload_thread_main(void* arg) if(fr_poll_for_quit(fast_reload_thread)) goto done; + if(!fr_load_config(fast_reload_thread)) + goto done_error; + if(fr_poll_for_quit(fast_reload_thread)) + goto done; + verbose(VERB_ALGO, "stop fast reload thread"); /* If this is not an exit due to quit earlier, send regular done. */ if(!fast_reload_thread->need_to_quit) diff --git a/daemon/unbound.c b/daemon/unbound.c index 457a08032..24060b740 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -682,6 +682,9 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode, * it would succeed on SIGHUP as well */ if(!cfg->use_syslog) log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir); + daemon->cfgfile = strdup(*cfgfile); + if(!daemon->cfgfile) + fatal_exit("out of memory in daemon cfgfile strdup"); } /**