Previously, bg_printenv *always* implied verbosity (see line 670). The
verbosity flag was subsequently (mis)used to ensure the environments are
actually being dumped in the case of printenv. There is no need for such
a misuse though: if verbosity is false, then dump_envs is (mostly)
a no-op. In that case, do not even call the function or in other words,
move the if-clause where it belongs.
Finally, this allows us to leave verbosity as it is (i.e. unset) in the
case of bg_printenv. Now it is possible to give the verbose flag
a proper meaning in the case of printenv, i.e. the output could actually
be more verbose when the flag is set. This is not in the scope of this
commit, though.
tools/bg_setenv.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
index 071c9fc..e564219 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -549,10 +549,8 @@ static void update_environment(BGENV *env)
static void dump_envs(void)
{
for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
- if (verbosity) {
- fprintf(stdout, "\n----------------------------\n");
- fprintf(stdout, " Config Partition #%d ", i);
- }
+ fprintf(stdout, "\n----------------------------\n");
+ fprintf(stdout, " Config Partition #%d ", i);
BGENV *env = bgenv_open_by_index(i);
if (!env) {
fprintf(stderr, "Error, could not read environment "
@@ -560,9 +558,7 @@ static void dump_envs(void)
i);
return;
}
- if (verbosity) {
- dump_env(env->data);
- }
+ dump_env(env->data);
bgenv_close(env);
}
}
@@ -667,7 +663,6 @@ int main(int argc, char **argv)
} else {
argp = &argp_printenv;
- verbosity = true;
}
struct arguments arguments;
@@ -703,13 +698,16 @@ int main(int argc, char **argv)
return 1;
}
- dump_envs();
-
if (!write_mode) {
+ dump_envs();
bgenv_finalize();
return 0;
}
+ if (verbosity) {
+ dump_envs();
+ }
+
BGENV *env_new = NULL;
BGENV *env_current;
--
2.33.0