qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] storage-daemon: include current command line option in the errors
@ 2021-02-26 11:03 Paolo Bonzini
  2021-02-26 13:44 ` Eric Blake
  2021-03-01 12:26 ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-02-26 11:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, qemu-block

Use the location management facilities that the emulator uses, so that
the current command line option appears in the error message.

Before:

  $ storage-daemon/qemu-storage-daemon --nbd key..=
  qemu-storage-daemon: Invalid parameter 'key..'

After:

  $ storage-daemon/qemu-storage-daemon --nbd key..=
  qemu-storage-daemon: --nbd key..=: Invalid parameter 'key..'

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 storage-daemon/qemu-storage-daemon.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c
index 9021a46b3a..a8f8d83f6f 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -152,6 +152,20 @@ static void init_qmp_commands(void)
                          qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
 }
 
+static int getopt_set_loc(int argc, char **argv, const char *optstring,
+                          const struct option *longopts)
+{
+    int c, save_index;
+
+    optarg = NULL;
+    save_index = optind;
+    c = getopt_long(argc, argv, optstring, longopts, NULL);
+    if (optarg) {
+        loc_set_cmdline(argv, save_index, MAX(1, optind - save_index));
+    }
+    return c;
+}
+
 static void process_options(int argc, char *argv[])
 {
     int c;
@@ -174,7 +188,7 @@ static void process_options(int argc, char *argv[])
      * they are given on the command lines. This means that things must be
      * defined first before they can be referenced in another option.
      */
-    while ((c = getopt_long(argc, argv, "hT:V", long_options, NULL)) != -1) {
+    while ((c = getopt_set_loc(argc, argv, "hT:V", long_options)) != -1) {
         switch (c) {
         case '?':
             exit(EXIT_FAILURE);
@@ -283,6 +297,7 @@ static void process_options(int argc, char *argv[])
         error_report("Unexpected argument: %s", argv[optind]);
         exit(EXIT_FAILURE);
     }
+    loc_set_none();
 }
 
 int main(int argc, char *argv[])
-- 
2.26.2



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

end of thread, other threads:[~2021-03-01 15:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-26 11:03 [PATCH] storage-daemon: include current command line option in the errors Paolo Bonzini
2021-02-26 13:44 ` Eric Blake
2021-03-01 12:26 ` Kevin Wolf
2021-03-01 15:09   ` Paolo Bonzini

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