diff options
author | Cyril Bur <cyril.bur@au1.ibm.com> | 2016-03-23 14:46:18 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-05-03 18:22:11 +1000 |
commit | abbdad0b42ed10af2d3dceb1c10fb8f153dc2368 (patch) | |
tree | 360ebfce8bfcf556c4eba514abcf79cfb20e079c /external | |
parent | 61bc50ac6d261353b8c3ff9605fb976f83c24aad (diff) | |
download | skiboot-abbdad0b42ed10af2d3dceb1c10fb8f153dc2368.zip skiboot-abbdad0b42ed10af2d3dceb1c10fb8f153dc2368.tar.gz skiboot-abbdad0b42ed10af2d3dceb1c10fb8f153dc2368.tar.bz2 |
external/pflash: Handle incorrect cmd-line options better
The current pflash cmd-line option parsing has two flaws.
Firstly, the error reporting leaves quite a bit to be desired. That is, when
invalid options or argument are found, not much reporting is done. This patch
addresses this.
Secondly, pflash doesn't detect when there are leftovers in argv. This often
signals a typo in what the user meant to do and could lead to the wrong
outcome. For example: `pflash -e -p zImage.next - P BOOTKERNEL` will do quite
the wrong thing.
This patch addresses both issues.
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'external')
-rw-r--r-- | external/pflash/pflash.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 7fc0de8..da7d7f5 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -550,13 +550,14 @@ int main(int argc, char *argv[]) {"debug", no_argument, NULL, 'g'}, {"side", required_argument, NULL, 'S'}, {"toc", required_argument, NULL, 'T'}, - {"clear", no_argument, NULL, 'c'} + {"clear", no_argument, NULL, 'c'}, + {NULL, 0, NULL, 0 } }; int c, oidx = 0; - c = getopt_long(argc, argv, "a:s:P:r:43Eemp:fdihvbtgS:T:c", + c = getopt_long(argc, argv, "+:a:s:P:r:43Eemp:fdihvbtgS:T:c", long_opts, &oidx); - if (c == EOF) + if (c == -1) break; switch(c) { case 'a': @@ -626,16 +627,36 @@ int main(int argc, char *argv[]) case 'c': do_clear = true; break; + case ':': + fprintf(stderr, "Unrecognised option \"%s\" to '%c'\n", optarg, optopt); + no_action = true; + break; + case '?': + fprintf(stderr, "Unrecognised option '%c'\n", optopt); + no_action = true; + break; default: - exit(1); + fprintf(stderr , "Encountered unknown error parsing options\n"); + no_action = true; } } + if (optind < argc) { + /* + * It appears not everything passed to pflash was an option, best to + * not continue + */ + while (optind < argc) + fprintf(stderr, "Unrecognised option or argument \"%s\"\n", argv[optind++]); + + no_action = true; + } + /* Check if we need to access the flash at all (which will * also tune them as a side effect */ - no_action = !erase && !program && !info && !do_read && - !enable_4B && !disable_4B && !tune && !do_clear; + no_action = no_action || (!erase && !program && !info && !do_read && + !enable_4B && !disable_4B && !tune && !do_clear); /* Nothing to do, if we didn't already, print usage */ if (no_action && !show_version) |