From 3de9e12f70c0312665bc628c8284fefe32cbd3cb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 28 May 2024 21:32:04 +0200 Subject: [PATCH] Change magic comment put next to config options which are forced through the environment Signed-off-by: DL6ER --- src/config/toml_writer.c | 14 ++++++-------- test/test_suite.bats | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/config/toml_writer.c b/src/config/toml_writer.c index afc6a35b..e8cde7dc 100644 --- a/src/config/toml_writer.c +++ b/src/config/toml_writer.c @@ -82,13 +82,6 @@ bool writeFTLtoml(const bool verbose) print_toml_allowed_values(conf_item->a, fp, 85, level-1); } - // Print info if this value is overwritten by an env var - if(conf_item->f & FLAG_ENV_VAR) - { - print_comment(fp, ">>> This config is overwritten by an environmental variable <<<", "", 85, level-1); - env_vars++; - } - // Write value indentTOML(fp, level-1); fprintf(fp, "%s = ", conf_item->p[level-1]); @@ -105,7 +98,12 @@ bool writeFTLtoml(const bool verbose) if(changed) { - fprintf(fp, " ### CHANGED, default = "); + + // Print info if this value is overwritten by an env var + if(conf_item->f & FLAG_ENV_VAR) + env_vars++; + + fprintf(fp, " ### CHANGED%s, default = ", conf_item->f & FLAG_ENV_VAR ? " (env)" : ""); writeTOMLvalue(fp, -1, conf_item->t, &conf_item->d); modified++; } diff --git a/test/test_suite.bats b/test/test_suite.bats index 94c04019..72b102bb 100644 --- a/test/test_suite.bats +++ b/test/test_suite.bats @@ -1326,10 +1326,9 @@ @test "Environmental variable is favored over config file" { # The config file has -10 but we set FTLCONF_misc_nice="-11" - run bash -c 'grep -B1 "nice = -11" /etc/pihole/pihole.toml' + run bash -c 'grep "nice = -11" /etc/pihole/pihole.toml' printf "%s\n" "${lines[@]}" - [[ ${lines[0]} == " # >>> This config is overwritten by an environmental variable <<<" ]] - [[ ${lines[1]} == " nice = -11 ### CHANGED, default = -10" ]] + [[ ${lines[2]} == " nice = -11 ### CHANGED (env), default = -10" ]] } @test "Correct number of environmental variables is logged" {