From aa339c8c68b9dd130a7d7dae053a60bcb6f98186 Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Wed, 3 Nov 2021 13:51:02 +0100
Subject: [PATCH] conf: update hostname from conf_new() only

This avoids problems with future changes and reduces overhead of conf_clone()
---
 doc/man/knot.conf.5in    | 2 +-
 doc/reference.rst        | 2 +-
 src/knot/conf/base.c     | 4 ++--
 src/knot/conf/base.h     | 9 ---------
 src/knot/server/server.c | 3 ---
 5 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/doc/man/knot.conf.5in b/doc/man/knot.conf.5in
index e767f51a2d..9f10528d55 100644
--- a/doc/man/knot.conf.5in
+++ b/doc/man/knot.conf.5in
@@ -229,7 +229,7 @@ class (\fI\%RFC 4892\fP). Set to an empty value to disable.
 .sp
 A DNS name server identifier (\fI\%RFC 5001\fP). Set to an empty value to disable.
 .sp
-\fIDefault:\fP FQDN hostname
+\fIDefault:\fP FQDN hostname at the moment of the daemon start
 .SS rundir
 .sp
 A path for storing run\-time data (PID file, unix sockets, etc.).
diff --git a/doc/reference.rst b/doc/reference.rst
index a0a09424d0..2e2a6963c1 100644
--- a/doc/reference.rst
+++ b/doc/reference.rst
@@ -184,7 +184,7 @@ nsid
 
 A DNS name server identifier (:rfc:`5001`). Set to an empty value to disable.
 
-*Default:* FQDN hostname
+*Default:* FQDN hostname at the moment of the daemon start
 
 .. _server_rundir:
 
diff --git a/src/knot/conf/base.c b/src/knot/conf/base.c
index 967317c892..ea106e7f79 100644
--- a/src/knot/conf/base.c
+++ b/src/knot/conf/base.c
@@ -91,7 +91,7 @@ int conf_refresh_txn(
 	return conf->api->txn_begin(conf->db, &conf->read_txn, KNOT_DB_RDONLY);
 }
 
-void conf_refresh_hostname(
+static void refresh_hostname(
 	conf_t *conf)
 {
 	if (conf == NULL) {
@@ -299,7 +299,7 @@ int conf_new(
 
 	// Cache the current hostname.
 	if (!(flags & CONF_FNOHOSTNAME)) {
-		conf_refresh_hostname(out);
+		refresh_hostname(out);
 	}
 
 	// Initialize cached values.
diff --git a/src/knot/conf/base.h b/src/knot/conf/base.h
index 62b6ee22b8..197b7273d0 100644
--- a/src/knot/conf/base.h
+++ b/src/knot/conf/base.h
@@ -193,15 +193,6 @@ int conf_refresh_txn(
 	conf_t *conf
 );
 
-/*!
- * Refreshes cached hostname.
- *
- * \param[in] conf  Configuration.
- */
-void conf_refresh_hostname(
-	conf_t *conf
-);
-
 /*!
  * Creates new or opens old configuration database.
  *
diff --git a/src/knot/server/server.c b/src/knot/server/server.c
index 9a66863c3c..5f1f64056e 100644
--- a/src/knot/server/server.c
+++ b/src/knot/server/server.c
@@ -855,9 +855,6 @@ static int reload_conf(conf_t *new_conf)
 		log_error("failed to migrate configuration (%s)", knot_strerror(ret));
 	}
 
-	/* Refresh hostname. */
-	conf_refresh_hostname(new_conf);
-
 	return KNOT_EOK;
 }
 
-- 
GitLab