Fix --noheader on fw_printenv
PATCH 1/1 Fix --noheader on fw_printenv
Using fw_printenv with --noheader fails:
root at nrr-922:~# fw_printenv --noheader arch ## Error: `-n' option requires exactly one argument
Whereas -n works:
root at nrr-922:~# fw_printenv -n arch
arm
The single argument it's expecting isn't taken from getopt parsing, but instead from the remaining argv arguments.
---
tools/env/fw_env_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/env/fw_env_main.c +1 -1
@@ -46,7 +46,7 @@ static struct option long_options[] = { {"config", required_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"script", required_argument, NULL, 's'}, - {"noheader", required_argument, NULL, 'n'}, + {"noheader", no_argument, NULL, 'n'}, {"lock", required_argument, NULL, 'l'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}
Signature · 1 line
2.7.4
PATCH 1/1 Fix --noheader on fw_printenv
Quoted 4 lines · Alex Kiernan
Using
fw_printenvwith --noheader fails:root at nrr-922:~#
fw_printenv--noheader arch ## Error: `-n' option requires exactly one argument
I think it would work with --noheader=arch
Quoted 8 lines
Whereas -n works:
root at nrr-922:~#
fw_printenv-n arch
armThe single argument it's expecting isn't taken from getopt parsing, but instead from the remaining argv arguments.
That makes sense. But the commit log text above is kind of unrelated/not relevant, I would just use this two lines as git message.
--
Stefan
Quoted 20 lines
Signed-off-by Alex Kiernan <[email protected]>---
tools/env/fw_env_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/env/fw_env_main.c +1
-1@@ -46,7 +46,7 @@ static struct option long_options[] = { {"config", required_argument, NULL, 'c'}, {"help", no_argument, NULL, 'h'}, {"script", required_argument, NULL, 's'}, - {"noheader", required_argument, NULL, 'n'}, + {"noheader", no_argument, NULL, 'n'}, {"lock", required_argument, NULL, 'l'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}
PATCH 1/1 Fix --noheader on fw_printenv
Quoted 8 lines · On Thu, Feb 8, 2018 at 3:37 PM, <[email protected]> wrote:
Quoted 4 lines · Alex Kiernan
Using
fw_printenvwith --noheader fails:root at nrr-922:~#
fw_printenv--noheader arch ## Error: `-n' option requires exactly one argumentI think it would work with --noheader=arch
It doesn't:
root at nrr-922:~# fw_printenv --noheader=arch ## Error: `-n' option requires exactly one argument
Probably I should fix the error too as it's misleading.
Quoted 12 lines
Quoted 8 lines
Whereas -n works:
root at nrr-922:~#
fw_printenv-n arch
armThe single argument it's expecting isn't taken from getopt parsing, but instead from the remaining argv arguments.
That makes sense. But the commit log text above is kind of unrelated/not relevant, I would just use this two lines as git message.
Happy to chop it down to the last two lines though as it does include the relevant details.
Signature · 1 line
Alex Kiernan
PATCH 1/1 Fix --noheader on fw_printenv
Quoted 10 lines · Alex Kiernan
Quoted 8 lines · On Thu, Feb 8, 2018 at 3:37 PM, <[email protected]> wrote:
Quoted 4 lines · Alex Kiernan
Using
fw_printenvwith --noheader fails:root at nrr-922:~#
fw_printenv--noheader arch ## Error: `-n' option requires exactly one argumentI think it would work with --noheader=arch
Quoted 7 lines
It doesn't:
root at nrr-922:~#
fw_printenv--noheader=arch ## Error: `-n' option requires exactly one argumentProbably 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?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Whereas -n works:
root at nrr-922:~#
fw_printenv-n arch
armThe single argument it's expecting isn't taken from getopt parsing, but instead from the remaining argv arguments.
Quoted 6 lines
Quoted 3 lines
That makes sense. But the commit log text above is kind of unrelated/not relevant, I would just use this two lines as git message.
Happy to chop it down to the last two lines though as it does include the relevant details.
IMHO the error is that struct option long_options ask for an argument whereas the optstring passed to getopt_long doesn't. The rather erratic is not really relevant and should not be mentioned.
--
Stefan
PATCH 1/1 Fix --noheader on fw_printenv
Quoted 16 lines · Stefan Agner
Quoted 15 lines · Alex Kiernan
Quoted 8 lines · On Thu, Feb 8, 2018 at 3:37 PM, <[email protected]> wrote:
Quoted 4 lines · Alex Kiernan
Using
fw_printenvwith --noheader fails:root at nrr-922:~#
fw_printenv--noheader arch ## Error: `-n' option requires exactly one argumentI think it would work with --noheader=arch
It doesn't:
root at nrr-922:~#
fw_printenv--noheader=arch ## Error: `-n' option requires exactly one argument
Quoted 9 lines
Quoted 2 lines
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 inparse_printenv_argsactually says argument "n" has no argument (no colon), so it actually is surprising that it prints that...Maybe this is from the
getopt_longcall inparse_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;
452
453 if (value_only && argc != 1) {
454 fprintf(stderr,
455 "## Error: `-n' option requires exactly
one argument\n");
456 return -1;
457 }
458
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 at nrr-922:~# fw_printenv --noheader=foo arch arm
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.
Signature · 1 line
Alex Kiernan