Skip to content

Commit

Permalink
linux-user: Add proper error messages for bad options
Browse files Browse the repository at this point in the history
This patch adds better support for diagnosing option
parser errors.  The previous implementation just printed
the usage text and exited when a bad option or argument
was found.  This made it very difficult to determine why
the usage was being displayed and it was doubly confusing
for cases like '--help' (it wasn't clear that --help was
actually an error).

Signed-off-by: Meador Inge <meadori@codesourcery.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
  • Loading branch information
meadori authored and Riku Voipio committed Sep 28, 2015
1 parent daaf8c8 commit 138940b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions linux-user/main.c
Expand Up @@ -4029,7 +4029,9 @@ static int parse_args(int argc, char **argv)
if (!strcmp(r, arginfo->argv)) {
if (arginfo->has_arg) {
if (optind >= argc) {
usage(1);
(void) fprintf(stderr,
"qemu: missing argument for option '%s'\n", r);
exit(1);
}
arginfo->handle_opt(argv[optind]);
optind++;
Expand All @@ -4042,12 +4044,14 @@ static int parse_args(int argc, char **argv)

/* no option matched the current argv */
if (arginfo->handle_opt == NULL) {
usage(1);
(void) fprintf(stderr, "qemu: unknown option '%s'\n", r);
exit(1);
}
}

if (optind >= argc) {
usage(1);
(void) fprintf(stderr, "qemu: no user program specified\n");
exit(1);
}

filename = argv[optind];
Expand Down

0 comments on commit 138940b

Please sign in to comment.