]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/qemu-xen.git/commitdiff
linux-user: Add proper error messages for bad options
authorMeador Inge <meadori@codesourcery.com>
Mon, 6 Jul 2015 18:03:40 +0000 (11:03 -0700)
committerRiku Voipio <riku.voipio@linaro.org>
Mon, 28 Sep 2015 13:04:20 +0000 (16:04 +0300)
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>
linux-user/main.c

index 58d8d8dff58798887ef51d346353c3ae9f330415..31aa4d98e43952a26c2ae1878e9126452905e5bd 100644 (file)
@@ -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++;
@@ -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];