summaryrefslogtreecommitdiff
path: root/src/app/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/config')
-rw-r--r--src/app/config/config.c1
-rw-r--r--src/app/config/confparse.c20
-rw-r--r--src/app/config/confparse.h1
-rw-r--r--src/app/config/statefile.c1
4 files changed, 23 insertions, 0 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 246f52a64a..d8b33aee73 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -904,6 +904,7 @@ get_options_mgr(void)
{
if (PREDICT_UNLIKELY(options_mgr == NULL)) {
options_mgr = config_mgr_new(&options_format);
+ config_mgr_freeze(options_mgr);
}
return options_mgr;
}
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 9d42263077..b086f8c94a 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -85,6 +85,10 @@ struct config_mgr_t {
smartlist_t *all_abbrevs;
/** A smartlist of config_deprecation_t for all configuration formats. */
smartlist_t *all_deprecations;
+ /** True if this manager has been frozen and cannot have any more formats
+ * added to it. A manager must be frozen before it can be used to construct
+ * or manipulate objects. */
+ bool frozen;
};
#define IDX_TOPLEVEL (-1)
@@ -112,6 +116,10 @@ config_mgr_register_fmt(config_mgr_t *mgr,
{
int i;
+ tor_assertf(!mgr->frozen,
+ "Tried to add a format to a configuration manager after "
+ "it had been frozen.");
+
/* register variables */
for (i = 0; fmt->vars[i].member.name; ++i) {
managed_var_t *mv = tor_malloc_zero(sizeof(managed_var_t));
@@ -161,6 +169,16 @@ config_mgr_get_obj(const config_mgr_t *mgr, const void *toplevel, int idx)
return config_mgr_get_obj_mutable(mgr, (void*)toplevel, idx);
}
+/**
+ * Mark a configuration manager as "frozen", so that no more formats can be
+ * added, and so that it can be used for manipulating configuration objects.
+ **/
+void
+config_mgr_freeze(config_mgr_t *mgr)
+{
+ mgr->frozen = true;
+}
+
/** Release all storage held in <b>mgr</b> */
void
config_mgr_free_(config_mgr_t *mgr)
@@ -208,6 +226,7 @@ config_mgr_assert_magic_ok(const config_mgr_t *mgr,
{
tor_assert(mgr);
tor_assert(options);
+ tor_assert(mgr->frozen);
struct_check_magic(options, &mgr->toplevel->magic);
}
@@ -221,6 +240,7 @@ config_mgr_assert_magic_ok(const config_mgr_t *mgr,
void *
config_new(const config_mgr_t *mgr)
{
+ tor_assert(mgr->frozen);
const config_format_t *fmt = mgr->toplevel;
void *opts = tor_malloc_zero(fmt->size);
struct_set_magic(opts, &fmt->magic);
diff --git a/src/app/config/confparse.h b/src/app/config/confparse.h
index edc7fa377a..83e886696e 100644
--- a/src/app/config/confparse.h
+++ b/src/app/config/confparse.h
@@ -73,6 +73,7 @@ typedef struct config_mgr_t config_mgr_t;
config_mgr_t *config_mgr_new(const config_format_t *toplevel_fmt);
void config_mgr_free_(config_mgr_t *mgr);
+void config_mgr_freeze(config_mgr_t *mgr);
#define config_mgr_free(mgr) \
FREE_AND_NULL(config_mgr_t, config_mgr_free_, (mgr))
struct smartlist_t *config_mgr_list_vars(const config_mgr_t *mgr);
diff --git a/src/app/config/statefile.c b/src/app/config/statefile.c
index a44bcf6fb5..93e35659df 100644
--- a/src/app/config/statefile.c
+++ b/src/app/config/statefile.c
@@ -183,6 +183,7 @@ get_state_mgr(void)
{
if (PREDICT_UNLIKELY(state_mgr == NULL)) {
state_mgr = config_mgr_new(&state_format);
+ config_mgr_freeze(state_mgr);
}
return state_mgr;
}