]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- fast-reload, reread config file from disk.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 4 Jan 2024 09:30:59 +0000 (10:30 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 4 Jan 2024 09:30:59 +0000 (10:30 +0100)
daemon/daemon.c
daemon/daemon.h
daemon/remote.c
daemon/unbound.c

index 9ee9a01a48300852d563b1c713227e5d239886c5..b229d2edb80ddf9e7edc1b36a08a23aff3a559cb 100644 (file)
@@ -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();
index aeb68bd9443051087270f395831c884aafbddea9..46cb5dbccc9338228797a83f63006b4e4d85f67a 100644 (file)
@@ -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;
 };
 
 /**
index 63ece5c5968d70b18bb43acc40ea545851c7348d..1d6b18978f6c446447eb9ff2e3c73af64434d677 100644 (file)
@@ -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)
index 457a08032857eb23fa260d13f8f0da80aa5a41e8..24060b740fbb52830592bcb7b2984abdce597e52 100644 (file)
@@ -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");
 }
 
 /**