All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH v2 2/2] storage-daemon: include current command line option in the errors
Date: Tue, 02 Mar 2021 07:38:02 +0100	[thread overview]
Message-ID: <87czwim56d.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20210301152844.291799-3-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 1 Mar 2021 10:28:44 -0500")

Paolo Bonzini <pbonzini@redhat.com> writes:

> 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..'
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

I have a similar patch in an unfinished branch.  You win :)

> ---
>  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 9aa82e7d96..78ddf619d4 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;
> +}
> +

I think this function is more widely applicable:

    $ git-grep -l getopt_long | xargs grep -l error_report
    qemu-img.c
    qemu-io.c
    qemu-nbd.c
    scsi/qemu-pr-helper.c
    storage-daemon/qemu-storage-daemon.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);
> @@ -275,12 +289,13 @@ static void process_options(int argc, char *argv[])
>                  break;
>              }
>          case 1:
> -            error_report("Unexpected argument: %s", optarg);
> +            error_report("Unexpected argument");
>              exit(EXIT_FAILURE);
>          default:
>              g_assert_not_reached();
>          }
>      }
> +    loc_set_none();
>  }
>  
>  int main(int argc, char *argv[])



  reply	other threads:[~2021-03-02  6:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 15:28 [PATCH v2 0/2] storage-daemon: include current command line option in the errors Paolo Bonzini
2021-03-01 15:28 ` [PATCH v2 1/2] storage-daemon: report unexpected arguments on the fly Paolo Bonzini
2021-03-01 15:38   ` Eric Blake
2021-03-01 16:29     ` Paolo Bonzini
2021-03-02  6:33     ` Markus Armbruster
2021-03-01 15:28 ` [PATCH v2 2/2] storage-daemon: include current command line option in the errors Paolo Bonzini
2021-03-02  6:38   ` Markus Armbruster [this message]
2021-03-01 18:24 ` [PATCH v2 0/2] " Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czwim56d.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.