Currently, the implementations of bg_setenv and bg_printenv are tightly coupled with each other, making it unnecessarily difficult to grasp, modify and extend the existing control flow.
Signed-off-by: Michael Adler <[email protected]> --- tools/bg_setenv.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c index 99da52b..c0144c1 100644 --- a/tools/bg_setenv.c +++ b/tools/bg_setenv.c @@ -639,6 +639,19 @@ static int dumpenv_to_file(char *envfilepath, bool verbosity, bool preserve_env) return result; } +/* This is the entrypoint for the command bg_printenv. */ +static int bg_printenv(const struct arguments *arguments) +{ + if (arguments->envfilepath) { + int result = printenv_from_file(arguments->envfilepath); + free(arguments->envfilepath); + return result; + } + dump_envs(); + bgenv_finalize(); + return 0; +} + int main(int argc, char **argv) { static struct argp argp_setenv = {options_setenv, parse_opt, NULL, doc}; @@ -671,19 +684,19 @@ int main(int argc, char **argv) return e; } + if (!write_mode) { + return bg_printenv(&arguments); + } + int result = 0; /* arguments are parsed, journal is filled */ /* is output to file or input from file ? */ if (arguments.envfilepath) { - if (write_mode) { - result = dumpenv_to_file(arguments.envfilepath, - arguments.verbosity, - arguments.preserve_env); - } else { - result = printenv_from_file(arguments.envfilepath); - } + result = dumpenv_to_file(arguments.envfilepath, + arguments.verbosity, + arguments.preserve_env); free(arguments.envfilepath); return result; } @@ -694,12 +707,6 @@ int main(int argc, char **argv) return 1; } - if (!write_mode) { - dump_envs(); - bgenv_finalize(); - return 0; - } - if (arguments.verbosity) { dump_envs(); } -- 2.33.1 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20211104092418.62237-5-michael.adler%40siemens.com.
