On Thu, Feb 8, 2018 at 4:40 PM, Stefan Agner <ste...@agner.ch> wrote:
> On 08.02.2018 17:17, Alex Kiernan wrote:
>> On Thu, Feb 8, 2018 at 3:37 PM,  <ste...@agner.ch> wrote:
>>> On 08.02.2018 10:35, Alex Kiernan wrote:
>>>> Using fw_printenv with --noheader fails:
>>>>   root@nrr-922:~# fw_printenv --noheader arch
>>>>   ## Error: `-n' option requires exactly one argument
>>> I think it would work with --noheader=arch
>> It doesn't:
>> root@nrr-922:~# fw_printenv --noheader=arch
>> ## Error: `-n' option requires exactly one argument
>> Probably I should fix the error too as it's misleading.
> This comes from getopt_long, so I don't think you can fix it. The getopt
> string in parse_printenv_args actually says argument "n" has no argument
> (no colon), so it actually is surprising that it prints that...
> Maybe this is from the getopt_long call in parse_common_args?

It's in fw_env.c:

449 int fw_printenv(int argc, char *argv[], int value_only, struct
env_opts *opts)
450 {
451         int i, rc = 0;
453         if (value_only && argc != 1) {
454                 fprintf(stderr,
455                         "## Error: `-n' option requires exactly
one argument\n");
456                 return -1;
457         }

You pass it one argument, getopt_long consumes it, the call to
getopt_long does nothing with the that argument and then this check
fails because there are no args left. Though you've made me realise it
does of course work if you call it like this!

root@nrr-922:~# fw_printenv --noheader=foo arch

I guess you could rewrite it so it's actually an optarg, not picked
out of argv, but you'd still want to check that there's no more args,
so really not sure you gain very much.

Alex Kiernan
U-Boot mailing list

Reply via email to