From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Richard W.M. Jones" <rjones@redhat.com>
Cc: kwolf@redhat.com, mreitz@redhat.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org, eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4] qemu-io: Add generic function for reinitializing optind.
Date: Fri, 18 Jan 2019 10:18:06 +0000 [thread overview]
Message-ID: <20190118101806.GF20660@redhat.com> (raw)
In-Reply-To: <20190118101114.11759-2-rjones@redhat.com>
On Fri, Jan 18, 2019 at 10:11:14AM +0000, Richard W.M. Jones wrote:
> On FreeBSD 11.2:
>
> $ nbdkit memory size=1M --run './qemu-io -f raw -c "aio_write 0 512" $nbd'
> Parsing error: non-numeric argument, or extraneous/unrecognized suffix -- aio_write
>
> After main option parsing, we reinitialize optind so we can parse each
> command. However reinitializing optind to 0 does not work on FreeBSD.
> What happens when you do this is optind remains 0 after the option
> parsing loop, and the result is we try to parse argv[optind] ==
> argv[0] == "aio_write" as if it was the first parameter.
>
> The FreeBSD manual page says:
>
> In order to use getopt() to evaluate multiple sets of arguments, or to
> evaluate a single set of arguments multiple times, the variable optreset
> must be set to 1 before the second and each additional set of calls to
> getopt(), and the variable optind must be reinitialized.
>
> (From the rest of the man page it is clear that optind must be
> reinitialized to 1).
>
> The glibc man page says:
>
> A program that scans multiple argument vectors, or rescans the same
> vector more than once, and wants to make use of GNU extensions such as
> '+' and '-' at the start of optstring, or changes the value of
> POSIXLY_CORRECT between scans, must reinitialize getopt() by resetting
> optind to 0, rather than the traditional value of 1. (Resetting to 0
> forces the invocation of an internal initialization routine that
> rechecks POSIXLY_CORRECT and checks for GNU extensions in optstring.)
>
> This commit introduces an OS-portability function called
> qemu_reset_optind which provides a way of resetting optind that works
> on FreeBSD and platforms that use optreset, while keeping it the same
> as now on other platforms.
>
> Note that the qemu codebase sets optind in many other places, but in
> those other places it's setting a local variable and not using getopt.
> This change is only needed in places where we are using getopt and the
> associated global variable optind.
>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
> configure | 14 ++++++++++++++
> include/qemu/osdep.h | 16 ++++++++++++++++
> qemu-img.c | 2 +-
> qemu-io-cmds.c | 2 +-
> 4 files changed, 32 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2019-01-18 10:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 10:11 [Qemu-devel] [PATCH v4] qemu-io: Add generic function for reinitializing optind Richard W.M. Jones
2019-01-18 10:11 ` Richard W.M. Jones
2019-01-18 10:18 ` Daniel P. Berrangé [this message]
2019-01-18 15:28 ` Eric Blake
2019-01-20 23:48 ` Max Reitz
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=20190118101806.GF20660@redhat.com \
--to=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
/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 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).