qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup
@ 2012-03-27 22:44 Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used Meador Inge
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Meador Inge @ 2012-03-27 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

This series is focused at cleaning up a few issues in the
GNU/Linux usermode driver's option parsing.  -h has been
fixed to exit with 0, a -help option has been added, proper
error messages have been added for unknown options and bad
arguments, and --foo is now excepted in addition to -foo.

Meador Inge (4):
  linux-user: Exit 0 when -h is used
  linux-user: Add -help
  linux-user: Add proper error messages for bad options
  linux-user: Treat --foo options the same as -foo

 linux-user/main.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used
  2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
@ 2012-03-27 22:44 ` Meador Inge
  2012-05-07 14:50   ` Andreas Färber
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 2/4] linux-user: Add -help Meador Inge
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Meador Inge @ 2012-03-27 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

Signed-off-by: Meador Inge <meadori@codesourcery.com>
---
 linux-user/main.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 962677e..aabce83 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -51,7 +51,7 @@ int have_guest_base;
 unsigned long reserved_va;
 #endif
 
-static void usage(void);
+static void usage(int exitcode);
 
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
 const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
@@ -2926,7 +2926,7 @@ void init_task_state(TaskState *ts)
 
 static void handle_arg_help(const char *arg)
 {
-    usage();
+    usage(0);
 }
 
 static void handle_arg_log(const char *arg)
@@ -2956,7 +2956,7 @@ static void handle_arg_set_env(const char *arg)
     r = p = strdup(arg);
     while ((token = strsep(&p, ",")) != NULL) {
         if (envlist_setenv(envlist, token) != 0) {
-            usage();
+            usage(1);
         }
     }
     free(r);
@@ -2968,7 +2968,7 @@ static void handle_arg_unset_env(const char *arg)
     r = p = strdup(arg);
     while ((token = strsep(&p, ",")) != NULL) {
         if (envlist_unsetenv(envlist, token) != 0) {
-            usage();
+            usage(1);
         }
     }
     free(r);
@@ -2984,7 +2984,7 @@ static void handle_arg_stack_size(const char *arg)
     char *p;
     guest_stack_size = strtoul(arg, &p, 0);
     if (guest_stack_size == 0) {
-        usage();
+        usage(1);
     }
 
     if (*p == 'M') {
@@ -3143,7 +3143,7 @@ struct qemu_argument arg_table[] = {
     {NULL, NULL, false, NULL, NULL, NULL}
 };
 
-static void usage(void)
+static void usage(int exitcode)
 {
     struct qemu_argument *arginfo;
     int maxarglen;
@@ -3204,7 +3204,7 @@ static void usage(void)
            "Note that if you provide several changes to a single variable\n"
            "the last change will stay in effect.\n");
 
-    exit(1);
+    exit(exitcode);
 }
 
 static int parse_args(int argc, char **argv)
@@ -3243,7 +3243,7 @@ static int parse_args(int argc, char **argv)
             if (!strcmp(r, arginfo->argv)) {
                 if (arginfo->has_arg) {
                     if (optind >= argc) {
-                        usage();
+                        usage(1);
                     }
                     arginfo->handle_opt(argv[optind]);
                     optind++;
@@ -3256,12 +3256,12 @@ static int parse_args(int argc, char **argv)
 
         /* no option matched the current argv */
         if (arginfo->handle_opt == NULL) {
-            usage();
+            usage(1);
         }
     }
 
     if (optind >= argc) {
-        usage();
+        usage(1);
     }
 
     filename = argv[optind];
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/4] linux-user: Add -help
  2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used Meador Inge
@ 2012-03-27 22:44 ` Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options Meador Inge
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Meador Inge @ 2012-03-27 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

This option is already available on the system mode
binaries.  It would be better if long options were
supported (i.e. --help), but this is okay for now.

Signed-off-by: Meador Inge <meadori@codesourcery.com>
---
 linux-user/main.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index aabce83..570178a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3104,6 +3104,8 @@ struct qemu_argument {
 };
 
 struct qemu_argument arg_table[] = {
+    {"help",       "",                 false, handle_arg_help,
+     "",           ""},
     {"h",          "",                 false, handle_arg_help,
      "",           "print this help"},
     {"g",          "QEMU_GDB",         true,  handle_arg_gdb,
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options
  2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 2/4] linux-user: Add -help Meador Inge
@ 2012-03-27 22:44 ` Meador Inge
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo Meador Inge
  2012-04-05  2:30 ` [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
  4 siblings, 0 replies; 9+ messages in thread
From: Meador Inge @ 2012-03-27 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

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>
---
 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo
  2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
                   ` (2 preceding siblings ...)
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options Meador Inge
@ 2012-03-27 22:44 ` Meador Inge
  2012-04-05  2:30 ` [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
  4 siblings, 0 replies; 9+ messages in thread
From: Meador Inge @ 2012-03-27 22:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

The system mode binaries provide a similiar alias
and it makes common options like --version and --help
work as expected.

Signed-off-by: Meador Inge <meadori@codesourcery.com>
---
 linux-user/main.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9616d8e..8f6ca0d 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3240,6 +3240,10 @@ static int parse_args(int argc, char **argv)
         if (!strcmp(r, "-")) {
             break;
         }
+        /* Treat --foo the same as -foo.  */
+        if (r[0] == '-') {
+            r++;
+        }
 
         for (arginfo = arg_table; arginfo->handle_opt != NULL; arginfo++) {
             if (!strcmp(r, arginfo->argv)) {
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup
  2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
                   ` (3 preceding siblings ...)
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo Meador Inge
@ 2012-04-05  2:30 ` Meador Inge
  2012-05-07 14:44   ` Meador Inge
  4 siblings, 1 reply; 9+ messages in thread
From: Meador Inge @ 2012-04-05  2:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

Ping.  Any comments on this series?

On 03/27/2012 05:44 PM, Meador Inge wrote:
> This series is focused at cleaning up a few issues in the
> GNU/Linux usermode driver's option parsing.  -h has been
> fixed to exit with 0, a -help option has been added, proper
> error messages have been added for unknown options and bad
> arguments, and --foo is now excepted in addition to -foo.
> 
> Meador Inge (4):
>   linux-user: Exit 0 when -h is used
>   linux-user: Add -help
>   linux-user: Add proper error messages for bad options
>   linux-user: Treat --foo options the same as -foo
> 
>  linux-user/main.c |   30 ++++++++++++++++++++----------
>  1 files changed, 20 insertions(+), 10 deletions(-)
> 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup
  2012-04-05  2:30 ` [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
@ 2012-05-07 14:44   ` Meador Inge
  2012-06-08 13:40     ` Meador Inge
  0 siblings, 1 reply; 9+ messages in thread
From: Meador Inge @ 2012-05-07 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

Ping ^ 2.

On 04/04/2012 09:30 PM, Meador Inge wrote:
> Ping.  Any comments on this series?
> 
> On 03/27/2012 05:44 PM, Meador Inge wrote:
>> This series is focused at cleaning up a few issues in the
>> GNU/Linux usermode driver's option parsing.  -h has been
>> fixed to exit with 0, a -help option has been added, proper
>> error messages have been added for unknown options and bad
>> arguments, and --foo is now excepted in addition to -foo.
>>
>> Meador Inge (4):
>>   linux-user: Exit 0 when -h is used
>>   linux-user: Add -help
>>   linux-user: Add proper error messages for bad options
>>   linux-user: Treat --foo options the same as -foo
>>
>>  linux-user/main.c |   30 ++++++++++++++++++++----------
>>  1 files changed, 20 insertions(+), 10 deletions(-)
>>
> 
> 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used
  2012-03-27 22:44 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used Meador Inge
@ 2012-05-07 14:50   ` Andreas Färber
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Färber @ 2012-05-07 14:50 UTC (permalink / raw)
  To: Meador Inge; +Cc: riku.voipio, qemu-devel

Am 28.03.2012 00:44, schrieb Meador Inge:
> Signed-off-by: Meador Inge <meadori@codesourcery.com>
> ---
>  linux-user/main.c |   20 ++++++++++----------
>  1 files changed, 10 insertions(+), 10 deletions(-)

Reviewed-by: Andreas Färber <afaerber@suse.de>

/-F

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup
  2012-05-07 14:44   ` Meador Inge
@ 2012-06-08 13:40     ` Meador Inge
  0 siblings, 0 replies; 9+ messages in thread
From: Meador Inge @ 2012-06-08 13:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

Ping ^ 3.

On 05/07/2012 09:44 AM, Meador Inge wrote:
> Ping ^ 2.
> 
> On 04/04/2012 09:30 PM, Meador Inge wrote:
>> Ping.  Any comments on this series?
>>
>> On 03/27/2012 05:44 PM, Meador Inge wrote:
>>> This series is focused at cleaning up a few issues in the
>>> GNU/Linux usermode driver's option parsing.  -h has been
>>> fixed to exit with 0, a -help option has been added, proper
>>> error messages have been added for unknown options and bad
>>> arguments, and --foo is now excepted in addition to -foo.
>>>
>>> Meador Inge (4):
>>>   linux-user: Exit 0 when -h is used
>>>   linux-user: Add -help
>>>   linux-user: Add proper error messages for bad options
>>>   linux-user: Treat --foo options the same as -foo
>>>
>>>  linux-user/main.c |   30 ++++++++++++++++++++----------
>>>  1 files changed, 20 insertions(+), 10 deletions(-)
>>>
>>
>>
> 
> 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-06-08 13:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
2012-03-27 22:44 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used Meador Inge
2012-05-07 14:50   ` Andreas Färber
2012-03-27 22:44 ` [Qemu-devel] [PATCH 2/4] linux-user: Add -help Meador Inge
2012-03-27 22:44 ` [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options Meador Inge
2012-03-27 22:44 ` [Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo Meador Inge
2012-04-05  2:30 ` [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
2012-05-07 14:44   ` Meador Inge
2012-06-08 13:40     ` Meador Inge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).