diff mbox

[PULL,03/13] linux-user: Add proper error messages for bad options

Message ID 138940bf08df1d8e9b862ad019a0d7d451e2413a.1443790691.git.riku.voipio@linaro.org
State Accepted
Commit 138940bf08df1d8e9b862ad019a0d7d451e2413a
Headers show

Commit Message

Riku Voipio Oct. 2, 2015, 1 p.m. UTC
From: Meador Inge <meadori@codesourcery.com>

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 | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index 58d8d8d..31aa4d9 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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];