Commit 42e58f73 authored by Daniel Salzman's avatar Daniel Salzman

conf: don't refresh hostname if not reload

parent d050273e
......@@ -137,12 +137,20 @@ int conf_refresh(
return conf->api->txn_begin(conf->db, &conf->read_txn, KNOT_DB_RDONLY);
}
static void init_values(
void conf_refresh_hostname(
conf_t *conf)
{
if (conf == NULL) {
return;
}
free(conf->hostname);
conf->hostname = sockaddr_hostname();
}
static void init_cache(
conf_t *conf)
{
conf->cache.srv_nsid = conf_get(conf, C_SRV, C_NSID);
conf->cache.srv_max_udp_payload = conf_get(conf, C_SRV, C_MAX_UDP_PAYLOAD);
conf->cache.srv_max_tcp_clients = conf_get(conf, C_SRV, C_MAX_TCP_CLIENTS);
......@@ -237,8 +245,13 @@ int conf_new(
// Initialize query modules list.
init_list(&out->query_modules);
// Cache the current hostname.
if (!(flags & CONF_FNOHOSTNAME)) {
out->hostname = sockaddr_hostname();
}
// Initialize cached values.
init_values(out);
init_cache(out);
*conf = out;
......@@ -293,8 +306,13 @@ int conf_clone(
// Initialize query modules list.
init_list(&out->query_modules);
// Reuse the hostname.
if (s_conf->hostname != NULL) {
out->hostname = strdup(s_conf->hostname);
}
// Initialize cached values.
init_values(out);
init_cache(out);
out->is_clone = true;
......@@ -748,7 +766,7 @@ int conf_import(
}
// Update cached values.
init_values(conf);
init_cache(conf);
// Reset the filename.
free(conf->filename);
......
......@@ -109,9 +109,10 @@ typedef struct {
* Configuration access flags.
*/
typedef enum {
CONF_FNONE = 0, /*!< Empty flag. */
CONF_FREADONLY = 1 << 0, /*!< Read only access. */
CONF_FNOCHECK = 1 << 1 /*!< Disabled confdb check. */
CONF_FNONE = 0, /*!< Empty flag. */
CONF_FREADONLY = 1 << 0, /*!< Read only access. */
CONF_FNOCHECK = 1 << 1, /*!< Disabled confdb check. */
CONF_FNOHOSTNAME = 1 << 2, /*!< Don't set the hostname. */
} conf_flag_t;
/*!
......@@ -130,6 +131,15 @@ int conf_refresh(
conf_t *conf
);
/*!
* Refreshes cached hostname.
*
* \param[in] conf Configuration.
*/
void conf_refresh_hostname(
conf_t *conf
);
/*!
* Creates new or opens old configuration database.
*
......
......@@ -269,7 +269,7 @@ static int ctl_reload(server_t *s, remote_cmdargs_t *a)
UNUSED(s);
UNUSED(a);
return server_reload(s, conf()->filename);
return server_reload(s, conf()->filename, true);
}
static int ctl_zone_status(server_t *s, remote_cmdargs_t *a)
......@@ -375,7 +375,7 @@ static int ctl_conf_commit(server_t *s, remote_cmdargs_t *a)
return ret;
}
return server_reload(s, NULL);
return server_reload(s, NULL, false);
}
static int ctl_conf_abort(server_t *s, remote_cmdargs_t *a)
......
......@@ -506,7 +506,7 @@ void server_wait(server_t *server)
}
}
int server_reload(server_t *server, const char *cf)
int server_reload(server_t *server, const char *cf, bool refresh_hostname)
{
if (server == NULL) {
return KNOT_EINVAL;
......@@ -545,6 +545,11 @@ int server_reload(server_t *server, const char *cf)
conf_activate_modules(new_conf, NULL, &new_conf->query_modules,
&new_conf->query_plan);
/* Refresh hostname. */
if (refresh_hostname) {
conf_refresh_hostname(new_conf);
}
/* Update to the new config. */
conf_update(new_conf);
......
......@@ -155,11 +155,12 @@ void server_wait(server_t *server);
/*!
* \brief Reload server configuration.
*
* \param server Server instance.
* \param cf Config file path.
* \param server Server instance.
* \param cf Config file path.
* \param refresh_hostname Refresh hostname indicator.
* \return
*/
int server_reload(server_t *server, const char *cf);
int server_reload(server_t *server, const char *cf, bool refresh_hostname);
/*!
* \brief Requests server to stop.
......
......@@ -94,7 +94,7 @@ static int set_config(const cmd_desc_t *desc, const char *confdb,
(src != NULL) ? src : "empty");
/* Prepare config flags. */
conf_flag_t conf_flags = CONF_FNONE;
conf_flag_t conf_flags = CONF_FNOHOSTNAME;
if (confdb != NULL && !(desc->flags & CMD_CONF_FWRITE)) {
conf_flags |= CONF_FREADONLY;
}
......
......@@ -245,7 +245,7 @@ static void event_loop(server_t *server, char *socket)
}
if (sig_req_reload) {
sig_req_reload = false;
server_reload(server, conf()->filename);
server_reload(server, conf()->filename, true);
}
/* Control interface. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment