qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad o


From: Meador Inge
Subject: [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options
Date: Tue, 27 Mar 2012 17:44:30 -0500

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 <address@hidden>
---
 linux-user/main.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 570178a..9616d8e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3245,7 +3245,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++;
@@ -3258,12 +3260,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: invalid option '%s'\n", r);
+        exit(1);
     }
 
     filename = argv[optind];
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]