qemu-e2k/include
Richard W.M. Jones d339d766d1 qemu-io: Add generic function for reinitializing optind.
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>
Message-id: 20190118101114.11759-2-rjones@redhat.com
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2019-01-31 00:38:19 +01:00
..
block qapi: add x-debug-query-block-graph 2019-01-31 00:38:19 +01:00
chardev char: add a QEMU_CHAR_FEATURE_GCONTEXT flag 2018-12-12 09:55:57 +01:00
crypto crypto: support multiple threads accessing one QCryptoBlock 2018-12-12 11:16:49 +00:00
disas target/mips: Add disassembler support for nanoMIPS 2018-10-25 22:13:33 +02:00
exec accel/tcg: Add cluster number to TCG TB hash 2019-01-29 11:46:06 +00:00
fpu include/fpu/softfloat: Fix compilation with Clang on s390x 2019-01-22 20:48:24 +00:00
hw qom/cpu: Add cluster_index to CPUState 2019-01-29 11:46:05 +00:00
io io: return 0 for EOF in TLS session read after shutdown 2018-11-19 11:16:46 -06:00
libdecnumber Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
migration vmstate: constify SaveVMHandlers 2019-01-23 15:51:47 +00:00
monitor monitor: Remove "x-oob", offer capability "oob" unconditionally 2018-12-12 10:28:27 +01:00
net virtio-net: support RSC v4/v6 tcp traffic for Windows HCK 2019-01-17 21:10:57 -05:00
qapi qapi: Eliminate indirection through qmp_event_get_func_emit() 2019-01-24 10:01:05 +01:00
qemu qemu-io: Add generic function for reinitializing optind. 2019-01-31 00:38:19 +01:00
qom qom/cpu: Add cluster_index to CPUState 2019-01-29 11:46:05 +00:00
scsi avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
standard-headers linux-headers: update 2018-10-12 11:32:18 +02:00
sysemu qapi: add x-debug-query-block-graph 2019-01-31 00:38:19 +01:00
ui ui: highres logo for sdl and gtk, bugfixes for vnc and egl. 2019-01-23 17:57:47 +00:00
elf.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
glib-compat.h glib-compat: add g_spawn_async_with_fds() fallback 2019-01-14 00:44:29 +01:00
qemu-common.h qemu-common.h: update copyright date to 2018 2018-10-16 17:52:06 +02:00
qemu-io.h qemu-io: Let command functions return error code 2018-06-11 16:18:45 +02:00
trace-tcg.h trace: get rid of generated-events.h/generated-events.c 2016-10-12 09:54:52 +02:00