On 2017-09-11 13:35, [ext] Andreas J. Reichel wrote:
> From: Reichel Andreas <[email protected]>
>
> For better usability, `bg_setenv`'s parameter -f is changed from
> `--file` to `--filepath` and now accepts a path, where `BGENV.DAT`
> is created so that it can directly be applied to the real environ-
> ment location.
>
> Signed-off-by: Andreas Reichel <[email protected]>
> ---
> docs/TODO.md | 1 -
> docs/USAGE.md | 12 ++++++------
> tools/bg_setenv.c | 20 ++++++++++++++------
> 3 files changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/docs/TODO.md b/docs/TODO.md
> index 40d5ba8..832f76b 100644
> --- a/docs/TODO.md
> +++ b/docs/TODO.md
> @@ -6,7 +6,6 @@
> the current working environment to the (latest-1) environment, so
> that if the current environment breaks, there is a backup with the
> latest values.
> - * Make `bg_setenv -f` take a path to where the `BGENV.DAT` is stored.
>
> * Application specific variables
> * applications may need to store their own variables into the
> diff --git a/docs/USAGE.md b/docs/USAGE.md
> index 7dd89ce..97a25cb 100644
> --- a/docs/USAGE.md
> +++ b/docs/USAGE.md
> @@ -98,13 +98,13 @@ This step first creates a custom label contained in
> `EFILABEL`, which is later
> used to specify the kernel location.
>
> ```
> -# mount /dev/sdX2 /mnt && cd /mnt
> -# echo -n "KERNEL1" | iconv -f ascii -t UTF-16LE > EFILABEL
> -# bg_setenv -f -r 1 --kernel="C:KERNEL1:vmlinuz-linux"
> --args="root=/dev/sdX4 noinitrd"
> +# mount /dev/sdX2 /mnt
> +# echo -n "KERNEL1" | iconv -f ascii -t UTF-16LE > /mnt/EFILABEL
> +# bg_setenv -f /mnt -r 1 --kernel="C:KERNEL1:vmlinuz-linux"
> --args="root=/dev/sdX4 noinitrd"
> # umount /mnt
> -# mount /dev/sdX3 /mnt && cd /mnt
> -# echo -n "KERNEL2" | iconv -f ascii -t UTF-16LE > EFILABEL
> -# bg_setenv -f -r 2 --kernel="C:KERNEL2:vmlinuz-linux"
> --args="root=/dev/sdX5 noinitrd"
> +# mount /dev/sdX3 /mnt
> +# echo -n "KERNEL2" | iconv -f ascii -t UTF-16LE > /mnt/EFILABEL
> +# bg_setenv -f /mnt -r 2 --kernel="C:KERNEL2:vmlinuz-linux"
> --args="root=/dev/sdX5 noinitrd"
> # umount /mnt
> ```
>
> diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
> index 5c313cf..c006bb6 100644
> --- a/tools/bg_setenv.c
> +++ b/tools/bg_setenv.c
> @@ -24,7 +24,9 @@ static struct argp_option options_setenv[] = {
> "above zero is updated."},
> {"revision", 'r', "REVISION", 0, "Set revision value"},
> {"testing", 't', "TESTING", 0, "Set test mode for environment"},
> - {"file", 'f', 0, 0, "Output environment to file"},
> + {"filepath", 'f', "ENVFILE_DIR", 0, "Output environment to file. Please "
"Please", hmm, that sounds still optional to me. :)
I can remove that word if I have no other findings.
> + "only provide an output path. The "
> + "file name is automatically appended."},
> {"watchdog", 'w', "WATCHDOG_TIMEOUT", 0, "Watchdog timeout in seconds"},
> {"confirm", 'c', 0, 0, "Confirm working environment"},
> {"update", 'u', 0, 0, "Automatically update oldest revision"},
> @@ -58,6 +60,8 @@ static bool part_specified = false;
>
> static bool verbosity = false;
>
> +static char *envfilepath = NULL;
Side note: Global vars are always 0-initialized. OTH one may argue that
NULL is not necessarily 0 - though it will be on our platforms.
> +
> static error_t parse_opt(int key, char *arg, struct argp_state *state)
> {
> struct arguments *arguments = state->input;
> @@ -138,6 +142,7 @@ static error_t parse_opt(int key, char *arg, struct
> argp_state *state)
> break;
> case 'f':
> arguments->output_to_file = true;
> + asprintf(&envfilepath, "%s/%s", arg, FAT_ENV_FILENAME);
> break;
> case 'c':
> VERBOSE(stdout,
> @@ -363,22 +368,25 @@ int main(int argc, char **argv)
> if (verbosity) {
> dump_env(&data);
> }
> - FILE *of = fopen(FAT_ENV_FILENAME, "wb");
> + FILE *of = fopen(envfilepath, "wb");
> if (of) {
> if (fwrite(&data, sizeof(BG_ENVDATA), 1, of) != 1) {
> fprintf(stderr,
> - "Error writing to output file.\n");
> - result = 1;
> + "Error writing to output file: %s\n",
> + strerror(errno));
> + result = errno;
> }
> if (fclose(of)) {
> fprintf(stderr, "Error closing output file.\n");
> result = 1;
> };
> - printf("Output written to %s.\n", FAT_ENV_FILENAME);
> + printf("Output written to %s.\n", envfilepath);
> } else {
> - fprintf(stderr, "Error opening output file.\n");
> + fprintf(stderr, "Error opening output file %s (%s).\n",
> + envfilepath, strerror(errno));
> result = 1;
> }
> + free(envfilepath);
> }
>
> return result;
>
Jan
--
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/efibootguard-dev/26aabfe6-3809-dadf-9131-be27f986ff5f%40siemens.com.
For more options, visit https://groups.google.com/d/optout.