Commit 57b592bc authored by Daniel Salzman's avatar Daniel Salzman

conf: get rid of conf_post_open

parent 7bc69184
......@@ -137,6 +137,19 @@ int conf_refresh(
return conf->api->txn_begin(conf->db, &conf->read_txn, KNOT_DB_RDONLY);
}
static void init_values(
conf_t *conf)
{
conf->hostname = sockaddr_hostname();
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);
conf->cache.srv_tcp_hshake_timeout = conf_get(conf, C_SRV, C_TCP_HSHAKE_TIMEOUT);
conf->cache.srv_tcp_idle_timeout = conf_get(conf, C_SRV, C_TCP_IDLE_TIMEOUT);
conf->cache.srv_tcp_reply_timeout = conf_get(conf, C_SRV, C_TCP_REPLY_TIMEOUT);
}
int conf_new(
conf_t **conf,
const yp_item_t *scheme,
......@@ -222,6 +235,9 @@ int conf_new(
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize cached values.
init_values(out);
*conf = out;
return KNOT_EOK;
......@@ -275,6 +291,9 @@ int conf_clone(
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize cached values.
init_values(out);
out->is_clone = true;
*conf = out;
......@@ -282,27 +301,6 @@ int conf_clone(
return KNOT_EOK;
}
int conf_post_open(
conf_t *conf)
{
if (conf == NULL) {
return KNOT_EINVAL;
}
conf->hostname = sockaddr_hostname();
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);
conf->cache.srv_tcp_hshake_timeout = conf_get(conf, C_SRV, C_TCP_HSHAKE_TIMEOUT);
conf->cache.srv_tcp_idle_timeout = conf_get(conf, C_SRV, C_TCP_IDLE_TIMEOUT);
conf->cache.srv_tcp_reply_timeout = conf_get(conf, C_SRV, C_TCP_REPLY_TIMEOUT);
conf_activate_modules(conf, NULL, &conf->query_modules, &conf->query_plan);
return KNOT_EOK;
}
void conf_update(
conf_t *conf)
{
......
......@@ -160,17 +160,6 @@ int conf_clone(
conf_t **conf
);
/*!
* Processes some additional operations and checks after configuration loading.
*
* \param[in] conf Configuration.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_post_open(
conf_t *conf
);
/*!
* Replaces the active configuration with the specified one.
*
......
......@@ -504,14 +504,9 @@ int server_reload(server_t *server, const char *cf)
log_info("reloading configuration database");
}
/* Run post-open config operations. */
ret = conf_post_open(new_conf);
if (ret != KNOT_EOK) {
log_error("failed to use configuration (%s)",
knot_strerror(ret));
conf_free(new_conf);
return ret;
}
/* Activate global query modules. */
conf_activate_modules(new_conf, NULL, &new_conf->query_modules,
&new_conf->query_plan);
/* Update to the new config. */
conf_update(new_conf);
......
......@@ -119,14 +119,6 @@ static int set_config(const cmd_desc_t *desc, const char *confdb,
}
}
/* Finalize the config (needed for conf check and cached items). */
ret = conf_post_open(new_conf);
if (ret != KNOT_EOK) {
log_error("failed to use configuration (%s)", knot_strerror(ret));
conf_free(new_conf);
return ret;
}
/* Update to the new config. */
conf_update(new_conf);
......
......@@ -332,13 +332,9 @@ static int set_config(const char *confdb, const char *config)
}
}
/* Run post-open config operations. */
ret = conf_post_open(new_conf);
if (ret != KNOT_EOK) {
log_fatal("failed to use configuration (%s)", knot_strerror(ret));
conf_free(new_conf);
return ret;
}
/* Activate global query modules. */
conf_activate_modules(new_conf, NULL, &new_conf->query_modules,
&new_conf->query_plan);
/* Update to the new config. */
conf_update(new_conf);
......
......@@ -27,25 +27,19 @@ static inline int test_conf(const char *conf_str, const yp_item_t *scheme)
scheme = conf_scheme;
}
conf_t *conf;
int ret = conf_new(&conf, scheme, NULL, CONF_FNONE);
conf_t *new_conf = NULL;
int ret = conf_new(&new_conf, scheme, NULL, CONF_FNONE);
if (ret != KNOT_EOK) {
return ret;
}
ret = conf_import(conf, conf_str, false);
ret = conf_import(new_conf, conf_str, false);
if (ret != KNOT_EOK) {
conf_free(conf);
conf_free(new_conf);
return ret;
}
ret = conf_post_open(conf);
if (ret != KNOT_EOK) {
conf_free(conf);
return ret;
}
conf_update(conf);
conf_update(new_conf);
return KNOT_EOK;
}
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