From: Jan Kiszka <[email protected]> This switches bg_setenv -f to a file name, rather than just a directory. The goal is to align bg_setenv and bg_printenv /wrt this argument.
In order to permit users to switch to the new scheme, detect the legacy call, issue a warning, but still append the default environment file name. This will eventually be dropped, though. Signed-off-by: Jan Kiszka <[email protected]> --- tools/bg_setenv.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c index 467cec4..d26eeed 100644 --- a/tools/bg_setenv.c +++ b/tools/bg_setenv.c @@ -13,6 +13,7 @@ */ #include <sys/queue.h> +#include <sys/stat.h> #include "env_api.h" #include "ebgenv.h" @@ -31,9 +32,9 @@ static struct argp_option options_setenv[] = { "the one with the smallest revision value above zero is updated."}, {"revision", 'r', "REVISION", 0, "Set revision value"}, {"ustate", 's', "USTATE", 0, "Set update status for environment"}, - {"filepath", 'f', "ENVFILE_DIR", 0, - "Output environment to file. Expects an output path where the file " - "name is automatically appended."}, + {"filepath", 'f', "ENVFILE", 0, + "Output environment to file. Expects an output file name, " + "usually called BGENV.DAT."}, {"watchdog", 'w', "WATCHDOG_TIMEOUT", 0, "Watchdog timeout in seconds"}, {"confirm", 'c', 0, 0, "Confirm working environment"}, {"update", 'u', 0, 0, "Automatically update oldest revision"}, @@ -355,14 +356,29 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) (uint8_t *)arg, strlen(arg) + 1); break; case 'f': - if (arguments->printenv) { - res = asprintf(&envfilepath, "%s", arg); - if (res == -1) { - return ENOMEM; + free(envfilepath); + envfilepath = NULL; + + /* compat mode, permitting "bg_setenv -f <dir>" */ + if (!arguments->printenv) { + struct stat sb; + + res = stat(arg, &sb); + if (res == 0 && S_ISDIR(sb.st_mode)) { + fprintf(stderr, + "WARNING: Using -f to specify only the " + "ouptut directory is deprecated.\n"); + res = asprintf(&envfilepath, "%s/%s", arg, + FAT_ENV_FILENAME); + if (res == -1) { + return ENOMEM; + } } - } else { - res = asprintf(&envfilepath, "%s/%s", arg, FAT_ENV_FILENAME); - if (res == -1) { + } + + if (!envfilepath) { + envfilepath = strdup(arg); + if (!envfilepath) { return ENOMEM; } } -- 2.26.2 -- 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/d0bc2e5b-3b03-4805-d110-b039344bedad%40siemens.com.
