X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fgrub2%2Fenv.c;h=3598927e0f295c5656e2fa93ee3192d32a18b92e;hp=1336824d1d92fb2bbc9d16945b4d3330135db6e1;hb=01e104dfb79a09bc28f8c5fb65bfe44596c25161;hpb=388e5c51b182e904c088d14c387f61162b07aee6 diff --git a/discover/grub2/env.c b/discover/grub2/env.c index 1336824..3598927 100644 --- a/discover/grub2/env.c +++ b/discover/grub2/env.c @@ -214,6 +214,7 @@ int builtin_save_env(struct grub2_script *script, int i, rc, len, siglen; char *buf, *envpath; const char *envfile; + bool using_dash_f = false; /* we only support local filesystems */ if (!dev->mounted) { @@ -222,9 +223,15 @@ int builtin_save_env(struct grub2_script *script, return -1; } - if (argc == 3 && !strcmp(argv[1], "-f")) + if (argc >= 2 && !strcmp(argv[1], "-f")) { + if (argc < 3) { + pb_log("save_env: for -f, need argument\n"); + return -1; + } + envfile = argv[2]; - else + using_dash_f = true; + } else envfile = default_envfile; envpath = talloc_asprintf(script, "%s/%s", @@ -241,7 +248,11 @@ int builtin_save_env(struct grub2_script *script, if (rc || len < siglen || memcmp(buf, signature, siglen)) goto err; - for (i = 1; i < argc; i++) { + /* For "-f", skip the "-f " arguments in picking the + * variables to save. */ + i = (using_dash_f ? 3 : 1); + + for (; i < argc; i++) { const char *name, *value; name = argv[i];