qemu-e2k/include/qemu
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
..
acl.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
atomic.h atomics: Set ATOMIC_REG_SIZE=8 for MIPS n32 2019-01-03 17:52:52 +01:00
atomic128.h tcg: Split CONFIG_ATOMIC128 2018-10-18 19:46:36 -07:00
base64.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
bcd.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
bitmap.h bitmap: provide to_le/from_le helpers 2017-09-22 14:11:25 +02:00
bitops.h vnc: replace hweight_long() with ctpopl() 2017-05-12 12:36:02 +02:00
bswap.h bswap: Add new stn_*_p() and ldn_*_p() memory access functions 2018-06-15 15:23:34 +01:00
buffer.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
compiler.h linux-user: Fix compilation with clang 3.4 2019-01-22 06:26:31 +01:00
config-file.h Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
coroutine.h block: Add missing locking in bdrv_co_drain_bh_cb() 2018-09-25 15:50:15 +02:00
coroutine_int.h coroutine: avoid co_queue_wakeup recursion 2018-03-27 13:05:28 +01:00
cpuid.h util: Introduce include/qemu/cpuid.h 2017-07-24 12:42:55 +01:00
crc32c.h include/qemu/crc32c.h: Rename include guards to match filename 2014-02-26 17:20:07 +00:00
cutils.h cutils: Fix qemu_strtosz() & friends to reject non-finite sizes 2018-12-13 19:10:06 +01:00
drm.h util: promote qemu_egl_rendernode_open() to libqemuutil 2018-08-27 10:51:44 +02:00
envlist.h misc: move include files to include/qemu/ 2012-12-19 08:32:39 +01:00
error-report.h qemu-error: make use of {error, warn}_report_once_cond 2018-09-24 17:13:07 +02:00
event_notifier.h Revert "qemu: add a cleanup callback function to EventNotifier" 2018-01-24 19:20:19 +02:00
fifo8.h Clean up header guards that don't match their file name 2016-07-12 16:19:16 +02:00
fifo32.h hw: Clean up includes 2016-06-07 18:19:23 +03:00
fprintf-fn.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
futex.h futex: add missing header guards 2017-10-16 20:57:13 +03:00
hbitmap.h Revert "hbitmap: Add @advance param to hbitmap_iter_next()" 2019-01-15 18:26:50 -05:00
help_option.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
host-utils.h includes: Replace QEMU_GNUC_PREREQ with "__has_builtin || !defined(__clang__)" 2018-12-12 10:01:13 +01:00
id.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
int128.h tcg: Add atomic128 helpers 2016-10-26 08:29:01 -07:00
iov.h avoid TABs in files that only contain a few 2019-01-11 15:46:56 +01:00
iova-tree.h util: remove redundant include of glib.h and add osdep.h 2018-06-29 12:22:28 +01:00
jhash.h Jhash: add linux kernel jhashtable in qemu 2016-09-27 17:54:21 +08:00
job.h blockjob: Lie better in child_job_drained_poll() 2018-09-25 15:50:15 +02:00
lockable.h lockable: workaround GCC link issue with ASAN 2018-03-06 14:01:27 +01:00
log-for-trace.h log-for-trace.h: Split out parts of log.h used by trace.h 2018-03-12 11:10:20 +00:00
log.h tcg: Optionally log FPU state in TCG -d cpu logging 2018-05-15 14:58:44 +01:00
main-loop.h qsp: track BQL callers explicitly 2018-08-23 18:46:25 +02:00
memfd.h hostmem-memfd: add checks before adding hostmem-memfd & properties 2018-10-02 18:47:55 +02:00
mmap-alloc.h exec, kvm, target-ppc: Move getrampagesize() to common code 2017-03-03 11:30:59 +11:00
module.h xen: add a mechanism to automatically create XenDevice-s... 2019-01-14 13:45:40 +00:00
notify.h notify: add NotiferWithReturn so notifier list can abort 2013-06-28 09:20:26 +02:00
option.h option: Make option help nicer to read 2018-11-05 15:17:48 +01:00
option_int.h qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
osdep.h qemu-io: Add generic function for reinitializing optind. 2019-01-31 00:38:19 +01:00
path.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
pmem.h migration/ram: ensure write persistence on loading all data to PMEM. 2018-08-10 13:29:39 +03:00
processor.h Drop remaining bits of ia64 host support 2018-02-05 18:09:45 +01:00
qdist.h clean-includes: run it once more 2016-06-16 18:39:03 +02:00
qht.h qht: constify qht_statistics_init 2018-09-26 08:55:54 -07:00
qsp.h qsp: support call site coalescing 2018-08-23 18:46:25 +02:00
queue.h qemu/queue.h: simplify reverse access to QTAILQ 2019-01-11 15:46:55 +01:00
range.h range: add some more functions 2019-01-09 22:09:31 -02:00
ratelimit.h ratelimit: don't align wait time with slices 2018-02-15 09:39:49 +00:00
rcu.h membarrier: introduce qemu/sys_membarrier.h 2018-03-12 16:12:47 +01:00
rcu_queue.h qemu/queue.h: reimplement QTAILQ without pointer-to-pointers 2019-01-11 15:46:55 +01:00
readline.h readline: add a free function 2018-01-16 14:54:50 +01:00
seqlock.h seqlock: add QemuLockable support 2018-08-23 18:46:25 +02:00
sockets.h sockets: move fd_is_socket() into common sockets code 2018-03-13 18:06:06 +00:00
stats64.h util: add stats64 module 2017-06-16 07:55:00 +08:00
sys_membarrier.h membarrier: add --enable-membarrier 2018-03-12 16:12:47 +01:00
systemd.h qemu-ga: obey LISTEN_PID when using systemd socket activation 2017-03-19 11:12:12 +01:00
thread-posix.h qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
thread-win32.h qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
thread.h include/qemu/thread.h: Document qemu_thread_atexit* API 2018-11-06 21:35:06 +01:00
throttle-options.h block: add throttle block filter driver 2017-09-06 10:12:02 +02:00
throttle.h Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
timed-average.h include: Clean up includes 2016-02-23 12:43:05 +00:00
timer.h * RTC fixes (Artem) 2018-10-19 19:01:07 +01:00
typedefs.h ui/console: Remove PixelFormat from qemu/typedefs.h 2019-01-22 05:14:33 +01:00
unicode.h json: Reject invalid UTF-8 sequences 2018-08-24 20:26:37 +02:00
units.h include: Add a comment to explain the origin of sizes' lookup table 2018-11-05 15:29:59 +01:00
uri.h Remove unused function declarations 2016-09-15 15:32:22 +03:00
uuid.h util: add is_equal to UUID API 2017-12-20 22:01:24 +08:00
vfio-helpers.h Clean up includes 2018-12-20 10:29:08 +01:00
win_dump_defs.h dump: move Windows dump structures definitions 2018-10-02 19:09:12 +02:00
xattr.h include: Fix typos found by codespell 2017-01-24 23:26:52 +03:00
xxhash.h xxhash: match output against the original xxhash32 2018-12-17 06:04:44 +03:00