summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/config/confparse.c11
-rw-r--r--src/test/test_confparse.c77
2 files changed, 49 insertions, 39 deletions
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index b086f8c94a..c7ee8f3010 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -169,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);
}
+/** Sorting helper for smartlist of managed_var_t */
+static int
+managed_var_cmp(const void **a, const void **b)
+{
+ const managed_var_t *mv1 = *(const managed_var_t**)a;
+ const managed_var_t *mv2 = *(const managed_var_t**)b;
+
+ return strcasecmp(mv1->cvar->member.name, mv2->cvar->member.name);
+}
+
/**
* 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.
@@ -176,6 +186,7 @@ config_mgr_get_obj(const config_mgr_t *mgr, const void *toplevel, int idx)
void
config_mgr_freeze(config_mgr_t *mgr)
{
+ smartlist_sort(mgr->all_vars, managed_var_cmp);
mgr->frozen = true;
}
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index 716384e2f6..1513c9323b 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -527,78 +527,77 @@ test_confparse_dump(void *arg)
/* Minimal version. */
dumped = config_dump(mgr, NULL, tst, 1, 0);
tt_str_op(dumped, OP_EQ,
- "s this is a\n"
- "fn /simple/test of the\n"
- "pos 77\n"
- "i 3\n"
- "u64 1000000000000\n"
- "interval 300\n"
- "msec_interval 300000\n"
- "mem 10\n"
- "dbl 6.060842\n"
- "boolean 1\n"
"autobool 0\n"
- "time 2019-06-14 13:58:51\n"
+ "boolean 1\n"
"csv configuration,parsing,system\n"
"csv_interval 10\n"
+ "dbl 6.060842\n"
+ "fn /simple/test of the\n"
+ "i 3\n"
+ "interval 300\n"
"lines hello\n"
"lines world\n"
+ "mem 10\n"
+ "VisibleLineB ABC\n"
"LineTypeA i d\n"
"LineTypeB i c\n"
+ "msec_interval 300000\n"
+ "pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
- "VisibleLineB ABC\n");
+ "s this is a\n"
+ "time 2019-06-14 13:58:51\n"
+ "u64 1000000000000\n");
- /* Maximal */
tor_free(dumped);
dumped = config_dump(mgr, NULL, tst, 0, 0);
tt_str_op(dumped, OP_EQ,
- "s this is a\n"
- "fn /simple/test of the\n"
- "pos 77\n"
- "i 3\n"
- "deprecated_int 3\n"
- "u64 1000000000000\n"
- "interval 300\n"
- "msec_interval 300000\n"
- "mem 10\n"
- "dbl 6.060842\n"
- "boolean 1\n"
"autobool 0\n"
- "time 2019-06-14 13:58:51\n"
+ "boolean 1\n"
"csv configuration,parsing,system\n"
"csv_interval 10\n"
+ "dbl 6.060842\n"
+ "deprecated_int 3\n"
+ "fn /simple/test of the\n"
+ "i 3\n"
+ "interval 300\n"
"lines hello\n"
"lines world\n"
+ "mem 10\n"
+ "VisibleLineB ABC\n"
"LineTypeA i d\n"
"LineTypeB i c\n"
+ "msec_interval 300000\n"
+ "pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
- "VisibleLineB ABC\n");
+ "s this is a\n"
+ "time 2019-06-14 13:58:51\n"
+ "u64 1000000000000\n");
/* commented */
tor_free(dumped);
dumped = config_dump(mgr, NULL, tst, 0, 1);
tt_str_op(dumped, OP_EQ,
- "s this is a\n"
- "fn /simple/test of the\n"
- "pos 77\n"
- "i 3\n"
- "# deprecated_int 3\n"
- "u64 1000000000000\n"
- "interval 300\n"
- "msec_interval 300000\n"
- "mem 10\n"
- "dbl 6.060842\n"
- "boolean 1\n"
"autobool 0\n"
- "time 2019-06-14 13:58:51\n"
+ "boolean 1\n"
"csv configuration,parsing,system\n"
"csv_interval 10\n"
+ "dbl 6.060842\n"
+ "# deprecated_int 3\n"
+ "fn /simple/test of the\n"
+ "i 3\n"
+ "interval 300\n"
"lines hello\n"
"lines world\n"
+ "mem 10\n"
+ "VisibleLineB ABC\n"
"LineTypeA i d\n"
"LineTypeB i c\n"
+ "msec_interval 300000\n"
+ "pos 77\n"
"routerset $FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"
- "VisibleLineB ABC\n");
+ "s this is a\n"
+ "time 2019-06-14 13:58:51\n"
+ "u64 1000000000000\n");
done:
config_free(mgr, tst);