Commit 12b03578 authored by Daniel Salzman's avatar Daniel Salzman

conf: fix query_modules list reuse upon conf-commit (adding zones)

parent 16de44cc
......@@ -168,7 +168,7 @@ static void dump_to_file(FILE *fd, server_t *server)
dump_ctx_t ctx = {
.fd = fd,
.query_modules = &conf()->query_modules,
.query_modules = conf()->query_modules,
};
// Dump global statistics.
......
......@@ -157,9 +157,6 @@ int conf_new(
}
memset(out, 0, sizeof(conf_t));
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize config schema.
int ret = yp_schema_copy(&out->schema, schema);
if (ret != KNOT_EOK) {
......@@ -174,6 +171,14 @@ int conf_new(
}
mm_ctx_mempool(out->mm, MM_DEFAULT_BLKSIZE);
// Initialize query modules list.
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
if (out->query_modules == NULL) {
ret = KNOT_ENOMEM;
goto new_error;
}
init_list(out->query_modules);
// Set the DB api.
out->api = knot_db_lmdb_api();
struct knot_db_lmdb_opts lmdb_opts = KNOT_DB_LMDB_OPTS_INITIALIZER;
......@@ -290,9 +295,19 @@ int conf_clone(
out->mm = s_conf->mm;
out->db = s_conf->db;
// Initialize query modules list.
out->query_modules = mm_alloc(out->mm, sizeof(list_t));
if (out->query_modules == NULL) {
yp_schema_free(out->schema);
free(out);
return KNOT_ENOMEM;
}
init_list(out->query_modules);
// Open common read-only transaction.
ret = conf_refresh_txn(out);
if (ret != KNOT_EOK) {
mm_free(out->mm, out->query_modules);
yp_schema_free(out->schema);
free(out);
return ret;
......@@ -308,9 +323,6 @@ int conf_clone(
out->hostname = strdup(s_conf->hostname);
}
// Initialize query modules list.
init_list(&out->query_modules);
// Initialize cached values.
init_cache(out);
......@@ -334,8 +346,7 @@ conf_t *conf_update(
conf->io.zones = s_conf->io.zones;
}
if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) {
list_dup(&conf->query_modules, &s_conf->query_modules,
sizeof(knotd_mod_t));
conf->query_modules = s_conf->query_modules;
conf->query_plan = s_conf->query_plan;
}
}
......@@ -353,7 +364,7 @@ conf_t *conf_update(
old_conf->io.zones = NULL;
}
if (flags & CONF_UPD_FMODULES) {
WALK_LIST_FREE(old_conf->query_modules);
old_conf->query_modules = NULL;
old_conf->query_plan = NULL;
}
if (!(flags & CONF_UPD_FNOFREE)) {
......@@ -388,7 +399,8 @@ void conf_free(
}
conf_mod_load_purge(conf, false);
conf_deactivate_modules(&conf->query_modules, &conf->query_plan);
conf_deactivate_modules(conf->query_modules, &conf->query_plan);
mm_free(conf->mm, conf->query_modules);
conf_mod_unload_shared(conf);
if (!conf->is_clone) {
......
......@@ -132,7 +132,7 @@ typedef struct {
/*! List of old schemas (lazy freed). */
old_schema_dynarray_t old_schemas;
/*! List of active query modules. */
list_t query_modules;
list_t *query_modules;
/*! Default query modules plan. */
struct query_plan *query_plan;
} conf_t;
......
......@@ -1328,7 +1328,7 @@ static int ctl_stats(ctl_args_t *args, ctl_cmd_t cmd)
// Process modules metrics.
if (section == NULL || strncasecmp(section, "mod-", strlen("mod-")) == 0) {
int ret = modules_stats(&conf()->query_modules, args, NULL);
int ret = modules_stats(conf()->query_modules, args, NULL);
if (ret != KNOT_EOK) {
send_error(args, knot_strerror(ret));
return ret;
......
......@@ -657,7 +657,7 @@ int server_reload(server_t *server)
return ret;
}
conf_activate_modules(new_conf, NULL, &new_conf->query_modules,
conf_activate_modules(new_conf, NULL, new_conf->query_modules,
&new_conf->query_plan);
}
......
......@@ -368,7 +368,7 @@ static int set_config(const char *confdb, const char *config)
}
/* Activate global query modules. */
conf_activate_modules(new_conf, NULL, &new_conf->query_modules,
conf_activate_modules(new_conf, NULL, new_conf->query_modules,
&new_conf->query_plan);
/* Update to the new config. */
......
......@@ -5,6 +5,7 @@
import os
from dnstest.libknot import libknot
from dnstest.module import ModStats
from dnstest.test import Test
from dnstest.utils import *
......@@ -12,6 +13,9 @@ t = Test()
knot = t.server("knot")
# Enable a global module to check the modules reuse doesn't crash the server.
knot.add_module(None, ModStats())
ctl = libknot.control.KnotCtl()
ZONE_NAME = "testzone."
......
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