:p
atchew
Login
From: Marc-André Lureau <marcandre.lureau@redhat.com> Hi, v2: - add patches to replace pipe() with g_unix_open_pipe() - add patch "Replace fcntl(0_NONBLOCK) with g_unix_set_fd_nonblocking()" - add patches to cleanup qemu_*block() usage (see "util: rename qemu_*block() socket functions" commit message) - fix lost braces during code move - replace TRUE/FALSE with true/false - add reviewed/ack-by tags Marc-André Lureau (26): Use QEMU_SANITIZE_THREAD Use QEMU_SANITIZE_ADDRESS include: move qemu_*_exec_dir() to cutils util/win32: simplify qemu_get_local_state_dir() tests: move libqtest.h back under qtest/ libqtest: split QMP part in libqmp tests: make libqmp buildable for win32 Use g_unix_set_fd_nonblocking() block: move fcntl_setfl() Replace qemu_pipe() with g_unix_open_pipe() util: replace pipe()+cloexec with g_unix_open_pipe() qga: replace pipe() with g_unix_open_pipe(CLOEXEC) tests: replace pipe() with g_unix_open_pipe(CLOEXEC) os-posix: replace pipe()+cloexec with g_unix_open_pipe(CLOEXEC) virtiofsd: replace pipe() with g_unix_open_pipe(CLOEXEC) io: replace pipe() with g_unix_open_pipe(CLOEXEC) Replace fcntl(0_NONBLOCK) with g_unix_set_fd_nonblocking() io: make qio_channel_command_new_pid() static chardev: replace qemu_set_nonblock() io: replace qemu_set{_non}block() qga: replace qemu_set_nonblock() hw: replace qemu_set_nonblock() ui: replace qemu_set_nonblock() net: replace qemu_set_nonblock() tests: replace qemu_set_nonblock() util: rename qemu_*block() socket functions docs/devel/qtest.rst | 2 +- include/io/channel-command.h | 25 -- include/qemu/atomic.h | 8 +- include/qemu/cutils.h | 7 + include/qemu/osdep.h | 12 - include/qemu/sockets.h | 6 +- include/sysemu/os-posix.h | 2 - subprojects/libvhost-user/include/compiler.h | 1 + tests/qtest/acpi-utils.h | 2 +- tests/qtest/boot-sector.h | 2 +- tests/qtest/fuzz/fuzz.h | 2 +- tests/qtest/libqmp.h | 52 ++++ tests/qtest/libqos/fw_cfg.h | 2 +- tests/qtest/libqos/i2c.h | 2 +- tests/qtest/libqos/libqos.h | 2 +- tests/qtest/libqos/malloc.h | 2 +- tests/qtest/libqos/pci.h | 2 +- tests/qtest/libqos/sdhci-cmd.h | 2 +- tests/qtest/libqtest-single.h | 2 +- tests/qtest/{libqos => }/libqtest.h | 29 +- tests/qtest/migration-helpers.h | 2 +- tests/qtest/tpm-emu.h | 2 +- block/file-posix.c | 15 + chardev/char-fd.c | 4 +- chardev/char-pty.c | 5 +- chardev/char-serial.c | 5 +- chardev/char-socket.c | 2 +- chardev/char-stdio.c | 5 +- contrib/ivshmem-server/ivshmem-server.c | 2 +- hw/hyperv/syndbg.c | 2 +- hw/input/virtio-input-host.c | 5 +- hw/misc/ivshmem.c | 2 +- hw/virtio/vhost-user.c | 2 +- hw/virtio/vhost-vsock.c | 11 +- io/channel-command.c | 46 +++- io/channel-file.c | 13 +- io/channel-socket.c | 6 +- net/l2tpv3.c | 2 +- net/socket.c | 10 +- net/tap-bsd.c | 4 +- net/tap-linux.c | 2 +- net/tap-solaris.c | 2 +- net/tap.c | 33 ++- os-posix.c | 3 +- qemu-io.c | 1 + qemu-nbd.c | 5 +- qga/channel-posix.c | 2 +- qga/commands-posix.c | 8 +- storage-daemon/qemu-storage-daemon.c | 1 + tests/qtest/ac97-test.c | 2 +- tests/qtest/ahci-test.c | 2 +- tests/qtest/am53c974-test.c | 2 +- tests/qtest/arm-cpu-features.c | 2 +- tests/qtest/aspeed_hace-test.c | 2 +- tests/qtest/boot-order-test.c | 2 +- tests/qtest/boot-sector.c | 2 +- tests/qtest/boot-serial-test.c | 2 +- tests/qtest/cdrom-test.c | 2 +- tests/qtest/dbus-display-test.c | 2 +- tests/qtest/dbus-vmstate-test.c | 2 +- tests/qtest/device-introspect-test.c | 2 +- tests/qtest/device-plug-test.c | 2 +- tests/qtest/drive_del-test.c | 2 +- tests/qtest/ds1338-test.c | 2 +- tests/qtest/e1000-test.c | 2 +- tests/qtest/eepro100-test.c | 2 +- tests/qtest/endianness-test.c | 2 +- tests/qtest/erst-test.c | 2 +- tests/qtest/es1370-test.c | 2 +- tests/qtest/fdc-test.c | 2 +- tests/qtest/fuzz-e1000e-test.c | 2 +- tests/qtest/fuzz-lsi53c895a-test.c | 2 +- tests/qtest/fuzz-megasas-test.c | 2 +- tests/qtest/fuzz-sb16-test.c | 2 +- tests/qtest/fuzz-sdcard-test.c | 2 +- tests/qtest/fuzz-virtio-scsi-test.c | 2 +- tests/qtest/fuzz-xlnx-dp-test.c | 2 +- tests/qtest/fuzz/fuzz.c | 3 +- tests/qtest/fuzz/generic_fuzz.c | 2 +- tests/qtest/fuzz/i440fx_fuzz.c | 2 +- tests/qtest/fuzz/qos_fuzz.c | 2 +- tests/qtest/fuzz/virtio_blk_fuzz.c | 2 +- tests/qtest/fuzz/virtio_net_fuzz.c | 4 +- tests/qtest/fuzz/virtio_scsi_fuzz.c | 2 +- tests/qtest/fw_cfg-test.c | 2 +- tests/qtest/hd-geo-test.c | 2 +- tests/qtest/hexloader-test.c | 2 +- tests/qtest/ide-test.c | 2 +- tests/qtest/ipoctal232-test.c | 2 +- tests/qtest/ivshmem-test.c | 7 +- tests/qtest/libqmp.c | 258 ++++++++++++++++++ .../libqos/aarch64-xlnx-zcu102-machine.c | 2 +- tests/qtest/libqos/ahci.c | 2 +- tests/qtest/libqos/arm-imx25-pdk-machine.c | 2 +- tests/qtest/libqos/arm-n800-machine.c | 2 +- tests/qtest/libqos/arm-raspi2-machine.c | 2 +- tests/qtest/libqos/arm-sabrelite-machine.c | 2 +- tests/qtest/libqos/arm-smdkc210-machine.c | 2 +- tests/qtest/libqos/arm-virt-machine.c | 2 +- .../qtest/libqos/arm-xilinx-zynq-a9-machine.c | 2 +- tests/qtest/libqos/e1000e.c | 2 +- tests/qtest/libqos/fw_cfg.c | 2 +- tests/qtest/libqos/i2c-imx.c | 2 +- tests/qtest/libqos/i2c-omap.c | 2 +- tests/qtest/libqos/i2c.c | 2 +- tests/qtest/libqos/libqos.c | 2 +- tests/qtest/libqos/pci-pc.c | 2 +- tests/qtest/libqos/pci-spapr.c | 2 +- tests/qtest/libqos/ppc64_pseries-machine.c | 2 +- tests/qtest/libqos/qgraph.c | 2 +- tests/qtest/libqos/qos_external.c | 2 +- tests/qtest/libqos/rtas.c | 2 +- tests/qtest/libqos/sdhci-cmd.c | 2 +- tests/qtest/libqos/sdhci.c | 2 +- tests/qtest/libqos/tpci200.c | 2 +- tests/qtest/libqos/usb.c | 2 +- tests/qtest/libqos/vhost-user-blk.c | 2 +- tests/qtest/libqos/virtio-9p.c | 2 +- tests/qtest/libqos/virtio-balloon.c | 2 +- tests/qtest/libqos/virtio-blk.c | 2 +- tests/qtest/libqos/virtio-iommu.c | 2 +- tests/qtest/libqos/virtio-mmio.c | 2 +- tests/qtest/libqos/virtio-net.c | 2 +- tests/qtest/libqos/virtio-pci.c | 2 +- tests/qtest/libqos/virtio-rng.c | 2 +- tests/qtest/libqos/virtio-scsi.c | 2 +- tests/qtest/libqos/virtio-serial.c | 2 +- tests/qtest/libqos/virtio.c | 2 +- tests/qtest/libqos/x86_64_pc-machine.c | 2 +- tests/qtest/libqtest.c | 207 +------------- tests/qtest/lpc-ich9-test.c | 2 +- tests/qtest/m48t59-test.c | 2 +- tests/qtest/machine-none-test.c | 2 +- tests/qtest/megasas-test.c | 2 +- tests/qtest/microbit-test.c | 2 +- tests/qtest/migration-test.c | 2 +- tests/qtest/modules-test.c | 2 +- tests/qtest/ne2000-test.c | 2 +- tests/qtest/npcm7xx_adc-test.c | 2 +- tests/qtest/npcm7xx_pwm-test.c | 2 +- tests/qtest/npcm7xx_sdhci-test.c | 2 +- tests/qtest/npcm7xx_smbus-test.c | 2 +- tests/qtest/npcm7xx_watchdog_timer-test.c | 2 +- tests/qtest/numa-test.c | 2 +- tests/qtest/nvme-test.c | 2 +- tests/qtest/pca9552-test.c | 2 +- tests/qtest/pci-test.c | 2 +- tests/qtest/pcnet-test.c | 2 +- tests/qtest/pflash-cfi02-test.c | 2 +- tests/qtest/pnv-xscom-test.c | 2 +- tests/qtest/prom-env-test.c | 2 +- tests/qtest/pvpanic-pci-test.c | 2 +- tests/qtest/pvpanic-test.c | 2 +- tests/qtest/pxe-test.c | 2 +- tests/qtest/q35-test.c | 2 +- tests/qtest/qmp-cmd-test.c | 2 +- tests/qtest/qmp-test.c | 2 +- tests/qtest/qom-test.c | 2 +- tests/qtest/rtas-test.c | 2 +- tests/qtest/sdhci-test.c | 2 +- tests/qtest/spapr-phb-test.c | 2 +- tests/qtest/tco-test.c | 2 +- tests/qtest/test-filter-mirror.c | 2 +- tests/qtest/test-filter-redirector.c | 2 +- tests/qtest/test-hmp.c | 2 +- tests/qtest/tpm-crb-swtpm-test.c | 2 +- tests/qtest/tpm-tis-device-swtpm-test.c | 2 +- tests/qtest/tpm-tis-swtpm-test.c | 2 +- tests/qtest/tpm-util.c | 2 +- tests/qtest/tulip-test.c | 2 +- tests/qtest/vhost-user-test.c | 4 +- tests/qtest/virtio-net-failover.c | 2 +- tests/qtest/virtio-rng-test.c | 2 +- tests/qtest/virtio-test.c | 2 +- tests/qtest/vmgenid-test.c | 2 +- tests/qtest/vmxnet3-test.c | 2 +- tests/qtest/wdt_ib700-test.c | 2 +- tests/qtest/xlnx-can-test.c | 2 +- tests/unit/socket-helpers.c | 2 +- tests/unit/test-crypto-tlssession.c | 8 +- tests/unit/test-io-channel-file.c | 2 +- tests/unit/test-iov.c | 4 +- tests/unit/test-qga.c | 2 +- tools/virtiofsd/helper.c | 2 +- ui/input-linux.c | 5 +- util/compatfd.c | 5 +- util/coroutine-ucontext.c | 2 +- util/cutils.c | 108 ++++++++ util/event_notifier-posix.c | 8 +- util/main-loop.c | 2 +- util/oslib-posix.c | 142 +--------- util/oslib-win32.c | 61 +---- util/vhost-user-server.c | 4 +- scripts/oss-fuzz/output_reproducer.py | 2 +- tests/qtest/libqos/meson.build | 5 +- tests/unit/meson.build | 2 +- 196 files changed, 758 insertions(+), 703 deletions(-) create mode 120000 subprojects/libvhost-user/include/compiler.h create mode 100644 tests/qtest/libqmp.h rename tests/qtest/{libqos => }/libqtest.h (95%) create mode 100644 tests/qtest/libqmp.c -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- include/qemu/atomic.h | 8 +++++--- subprojects/libvhost-user/include/compiler.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) create mode 120000 subprojects/libvhost-user/include/compiler.h diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -XXX,XX +XXX,XX @@ #ifndef QEMU_ATOMIC_H #define QEMU_ATOMIC_H +#include "compiler.h" + /* Compiler barrier */ #define barrier() ({ asm volatile("" ::: "memory"); (void)0; }) @@ -XXX,XX +XXX,XX @@ * no processors except Alpha need a barrier here. Leave it in if * using Thread Sanitizer to avoid warnings, otherwise optimize it away. */ -#if defined(__SANITIZE_THREAD__) +#ifdef QEMU_SANITIZE_THREAD #define smp_read_barrier_depends() ({ barrier(); __atomic_thread_fence(__ATOMIC_CONSUME); }) #elif defined(__alpha__) #define smp_read_barrier_depends() asm volatile("mb":::"memory") @@ -XXX,XX +XXX,XX @@ /* See above: most compilers currently treat consume and acquire the * same, but this slows down qatomic_rcu_read unnecessarily. */ -#ifdef __SANITIZE_THREAD__ +#ifdef QEMU_SANITIZE_THREAD #define qatomic_rcu_read__nocheck(ptr, valptr) \ __atomic_load(ptr, valptr, __ATOMIC_CONSUME); #else @@ -XXX,XX +XXX,XX @@ #define qatomic_mb_read(ptr) \ qatomic_load_acquire(ptr) -#if !defined(__SANITIZE_THREAD__) && \ +#if !defined(QEMU_SANITIZE_THREAD) && \ (defined(__i386__) || defined(__x86_64__) || defined(__s390x__)) /* This is more efficient than a store plus a fence. */ # define qatomic_mb_set(ptr, i) ((void)qatomic_xchg(ptr, i)) diff --git a/subprojects/libvhost-user/include/compiler.h b/subprojects/libvhost-user/include/compiler.h new file mode 120000 index XXXXXXX..XXXXXXX --- /dev/null +++ b/subprojects/libvhost-user/include/compiler.h @@ -0,0 +1 @@ +../../../include/qemu/compiler.h \ No newline at end of file -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/qtest/fdc-test.c | 2 +- util/coroutine-ucontext.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -XXX,XX +XXX,XX @@ static void fuzz_registers(void) static bool qtest_check_clang_sanitizer(void) { -#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) +#ifdef QEMU_SANITIZE_ADDRESS return true; #else g_test_skip("QEMU not configured using --enable-sanitizers"); diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index XXXXXXX..XXXXXXX 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -XXX,XX +XXX,XX @@ #include <valgrind/valgrind.h> #endif -#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) +#ifdef QEMU_SANITIZE_ADDRESS #ifdef CONFIG_ASAN_IFACE_FIBER #define CONFIG_ASAN 1 #include <sanitizer/asan_interface.h> -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The function is required by get_relocated_path() (already in cutils), and used by qemu-ga and may be generally useful. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/qemu/cutils.h | 7 ++ include/qemu/osdep.h | 8 -- qemu-io.c | 1 + storage-daemon/qemu-storage-daemon.c | 1 + tests/qtest/fuzz/fuzz.c | 1 + util/cutils.c | 108 +++++++++++++++++++++++++++ util/oslib-posix.c | 81 -------------------- util/oslib-win32.c | 36 --------- 8 files changed, 118 insertions(+), 125 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -XXX,XX +XXX,XX @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n); */ int qemu_pstrcmp0(const char **str1, const char **str2); +/* Find program directory, and save it for later usage with + * qemu_get_exec_dir(). + * Try OS specific API first, if not working, parse from argv0. */ +void qemu_init_exec_dir(const char *argv0); + +/* Get the saved exec dir. */ +const char *qemu_get_exec_dir(void); /** * get_relocated_path: diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -XXX,XX +XXX,XX @@ bool fips_get_state(void); */ char *qemu_get_local_state_dir(void); -/* Find program directory, and save it for later usage with - * qemu_get_exec_dir(). - * Try OS specific API first, if not working, parse from argv0. */ -void qemu_init_exec_dir(const char *argv0); - -/* Get the saved exec dir. */ -const char *qemu_get_exec_dir(void); - /** * qemu_getauxval: * @type: the auxiliary vector key to lookup diff --git a/qemu-io.c b/qemu-io.c index XXXXXXX..XXXXXXX 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -XXX,XX +XXX,XX @@ #endif #include "qemu/help-texts.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qemu-io.h" #include "qemu/error-report.h" diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index XXXXXXX..XXXXXXX 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -XXX,XX +XXX,XX @@ #include "qemu/help-texts.h" #include "qemu-version.h" +#include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/help_option.h" diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -XXX,XX +XXX,XX @@ #include <wordexp.h> +#include "qemu/cutils.h" #include "qemu/datadir.h" #include "sysemu/sysemu.h" #include "sysemu/qtest.h" diff --git a/util/cutils.c b/util/cutils.c index XXXXXXX..XXXXXXX 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -XXX,XX +XXX,XX @@ static inline const char *next_component(const char *dir, int *p_len) return dir; } +static const char *exec_dir; + +void qemu_init_exec_dir(const char *argv0) +{ +#ifdef G_OS_WIN32 + char *p; + char buf[MAX_PATH]; + DWORD len; + + if (exec_dir) { + return; + } + + len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); + if (len == 0) { + return; + } + + buf[len] = 0; + p = buf + len - 1; + while (p != buf && *p != '\\') { + p--; + } + *p = 0; + if (access(buf, R_OK) == 0) { + exec_dir = g_strdup(buf); + } else { + exec_dir = CONFIG_BINDIR; + } +#else + char *p = NULL; + char buf[PATH_MAX]; + + if (exec_dir) { + return; + } + +#if defined(__linux__) + { + int len; + len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); + if (len > 0) { + buf[len] = 0; + p = buf; + } + } +#elif defined(__FreeBSD__) \ + || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) + { +#if defined(__FreeBSD__) + static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; +#else + static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; +#endif + size_t len = sizeof(buf) - 1; + + *buf = '\0'; + if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && + *buf) { + buf[sizeof(buf) - 1] = '\0'; + p = buf; + } + } +#elif defined(__APPLE__) + { + char fpath[PATH_MAX]; + uint32_t len = sizeof(fpath); + if (_NSGetExecutablePath(fpath, &len) == 0) { + p = realpath(fpath, buf); + if (!p) { + return; + } + } + } +#elif defined(__HAIKU__) + { + image_info ii; + int32_t c = 0; + + *buf = '\0'; + while (get_next_image_info(0, &c, &ii) == B_OK) { + if (ii.type == B_APP_IMAGE) { + strncpy(buf, ii.name, sizeof(buf)); + buf[sizeof(buf) - 1] = 0; + p = buf; + break; + } + } + } +#endif + /* If we don't have any way of figuring out the actual executable + location then try argv[0]. */ + if (!p && argv0) { + p = realpath(argv0, buf); + } + if (p) { + exec_dir = g_path_get_dirname(p); + } else { + exec_dir = CONFIG_BINDIR; + } +#endif +} + +const char *qemu_get_exec_dir(void) +{ + return exec_dir; +} + char *get_relocated_path(const char *dir) { size_t prefix_len = strlen(CONFIG_PREFIX); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ void qemu_set_tty_echo(int fd, bool echo) tcsetattr(fd, TCSANOW, &tty); } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - char *p = NULL; - char buf[PATH_MAX]; - - if (exec_dir) { - return; - } - -#if defined(__linux__) - { - int len; - len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); - if (len > 0) { - buf[len] = 0; - p = buf; - } - } -#elif defined(__FreeBSD__) \ - || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) - { -#if defined(__FreeBSD__) - static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; -#else - static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; -#endif - size_t len = sizeof(buf) - 1; - - *buf = '\0'; - if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && - *buf) { - buf[sizeof(buf) - 1] = '\0'; - p = buf; - } - } -#elif defined(__APPLE__) - { - char fpath[PATH_MAX]; - uint32_t len = sizeof(fpath); - if (_NSGetExecutablePath(fpath, &len) == 0) { - p = realpath(fpath, buf); - if (!p) { - return; - } - } - } -#elif defined(__HAIKU__) - { - image_info ii; - int32_t c = 0; - - *buf = '\0'; - while (get_next_image_info(0, &c, &ii) == B_OK) { - if (ii.type == B_APP_IMAGE) { - strncpy(buf, ii.name, sizeof(buf)); - buf[sizeof(buf) - 1] = 0; - p = buf; - break; - } - } - } -#endif - /* If we don't have any way of figuring out the actual executable - location then try argv[0]. */ - if (!p && argv0) { - p = realpath(argv0, buf); - } - if (p) { - exec_dir = g_path_get_dirname(p); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - #ifdef CONFIG_LINUX static void sigbus_handler(int signal, siginfo_t *siginfo, void *ctx) #else /* CONFIG_LINUX */ diff --git a/util/oslib-win32.c b/util/oslib-win32.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -XXX,XX +XXX,XX @@ void qemu_set_tty_echo(int fd, bool echo) } } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - - char *p; - char buf[MAX_PATH]; - DWORD len; - - if (exec_dir) { - return; - } - - len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); - if (len == 0) { - return; - } - - buf[len] = 0; - p = buf + len - 1; - while (p != buf && *p != '\\') { - p--; - } - *p = 0; - if (access(buf, R_OK) == 0) { - exec_dir = g_strdup(buf); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - int getpagesize(void) { SYSTEM_INFO system_info; -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> SHGetFolderPath() is a deprecated API: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha It is a wrapper for SHGetKnownFolderPath() and CSIDL_COMMON_PATH is mapped to FOLDERID_ProgramData: https://docs.microsoft.com/en-us/windows/win32/shell/csidl g_get_system_data_dirs() is a suitable replacement, as it will have FOLDERID_ProgramData in the returned list. However, it follows the XDG Base Directory Specification, if `XDG_DATA_DIRS` is defined, it will be returned instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- util/oslib-win32.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -XXX,XX +XXX,XX @@ #include "qemu/error-report.h" #include <malloc.h> -/* this must come after including "trace.h" */ -#include <shlobj.h> - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; @@ -XXX,XX +XXX,XX @@ int qemu_get_thread_id(void) char * qemu_get_local_state_dir(void) { - HRESULT result; - char base_path[MAX_PATH+1] = ""; + const char * const *data_dirs = g_get_system_data_dirs(); - result = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, - /* SHGFP_TYPE_CURRENT */ 0, base_path); - if (result != S_OK) { - /* misconfigured environment */ - g_critical("CSIDL_COMMON_APPDATA unavailable: %ld", (long)result); - abort(); - } - return g_strdup(base_path); + g_assert(data_dirs && data_dirs[0]); + + return g_strdup(data_dirs[0]); } void qemu_set_tty_echo(int fd, bool echo) -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Since commit a2ce7dbd917 ("meson: convert tests/qtest to meson"), libqtest.h is under libqos/ directory, while libqtest.c is still in qtest/. Move back to its original location to avoid mixing with libqos/. Suggested-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> --- docs/devel/qtest.rst | 2 +- tests/qtest/acpi-utils.h | 2 +- tests/qtest/boot-sector.h | 2 +- tests/qtest/fuzz/fuzz.h | 2 +- tests/qtest/libqos/fw_cfg.h | 2 +- tests/qtest/libqos/i2c.h | 2 +- tests/qtest/libqos/libqos.h | 2 +- tests/qtest/libqos/malloc.h | 2 +- tests/qtest/libqos/pci.h | 2 +- tests/qtest/libqos/sdhci-cmd.h | 2 +- tests/qtest/libqtest-single.h | 2 +- tests/qtest/{libqos => }/libqtest.h | 0 tests/qtest/migration-helpers.h | 2 +- tests/qtest/tpm-emu.h | 2 +- tests/qtest/ac97-test.c | 2 +- tests/qtest/ahci-test.c | 2 +- tests/qtest/am53c974-test.c | 2 +- tests/qtest/arm-cpu-features.c | 2 +- tests/qtest/aspeed_hace-test.c | 2 +- tests/qtest/boot-order-test.c | 2 +- tests/qtest/boot-sector.c | 2 +- tests/qtest/boot-serial-test.c | 2 +- tests/qtest/cdrom-test.c | 2 +- tests/qtest/dbus-display-test.c | 2 +- tests/qtest/dbus-vmstate-test.c | 2 +- tests/qtest/device-introspect-test.c | 2 +- tests/qtest/device-plug-test.c | 2 +- tests/qtest/drive_del-test.c | 2 +- tests/qtest/ds1338-test.c | 2 +- tests/qtest/e1000-test.c | 2 +- tests/qtest/eepro100-test.c | 2 +- tests/qtest/endianness-test.c | 2 +- tests/qtest/erst-test.c | 2 +- tests/qtest/es1370-test.c | 2 +- tests/qtest/fuzz-e1000e-test.c | 2 +- tests/qtest/fuzz-lsi53c895a-test.c | 2 +- tests/qtest/fuzz-megasas-test.c | 2 +- tests/qtest/fuzz-sb16-test.c | 2 +- tests/qtest/fuzz-sdcard-test.c | 2 +- tests/qtest/fuzz-virtio-scsi-test.c | 2 +- tests/qtest/fuzz-xlnx-dp-test.c | 2 +- tests/qtest/fuzz/fuzz.c | 2 +- tests/qtest/fuzz/generic_fuzz.c | 2 +- tests/qtest/fuzz/i440fx_fuzz.c | 2 +- tests/qtest/fuzz/qos_fuzz.c | 2 +- tests/qtest/fuzz/virtio_blk_fuzz.c | 2 +- tests/qtest/fuzz/virtio_net_fuzz.c | 2 +- tests/qtest/fuzz/virtio_scsi_fuzz.c | 2 +- tests/qtest/fw_cfg-test.c | 2 +- tests/qtest/hd-geo-test.c | 2 +- tests/qtest/hexloader-test.c | 2 +- tests/qtest/ide-test.c | 2 +- tests/qtest/ipoctal232-test.c | 2 +- tests/qtest/ivshmem-test.c | 2 +- tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c | 2 +- tests/qtest/libqos/ahci.c | 2 +- tests/qtest/libqos/arm-imx25-pdk-machine.c | 2 +- tests/qtest/libqos/arm-n800-machine.c | 2 +- tests/qtest/libqos/arm-raspi2-machine.c | 2 +- tests/qtest/libqos/arm-sabrelite-machine.c | 2 +- tests/qtest/libqos/arm-smdkc210-machine.c | 2 +- tests/qtest/libqos/arm-virt-machine.c | 2 +- tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c | 2 +- tests/qtest/libqos/e1000e.c | 2 +- tests/qtest/libqos/fw_cfg.c | 2 +- tests/qtest/libqos/i2c-imx.c | 2 +- tests/qtest/libqos/i2c-omap.c | 2 +- tests/qtest/libqos/i2c.c | 2 +- tests/qtest/libqos/libqos.c | 2 +- tests/qtest/libqos/pci-pc.c | 2 +- tests/qtest/libqos/pci-spapr.c | 2 +- tests/qtest/libqos/ppc64_pseries-machine.c | 2 +- tests/qtest/libqos/qgraph.c | 2 +- tests/qtest/libqos/qos_external.c | 2 +- tests/qtest/libqos/rtas.c | 2 +- tests/qtest/libqos/sdhci-cmd.c | 2 +- tests/qtest/libqos/sdhci.c | 2 +- tests/qtest/libqos/tpci200.c | 2 +- tests/qtest/libqos/usb.c | 2 +- tests/qtest/libqos/vhost-user-blk.c | 2 +- tests/qtest/libqos/virtio-9p.c | 2 +- tests/qtest/libqos/virtio-balloon.c | 2 +- tests/qtest/libqos/virtio-blk.c | 2 +- tests/qtest/libqos/virtio-iommu.c | 2 +- tests/qtest/libqos/virtio-mmio.c | 2 +- tests/qtest/libqos/virtio-net.c | 2 +- tests/qtest/libqos/virtio-pci.c | 2 +- tests/qtest/libqos/virtio-rng.c | 2 +- tests/qtest/libqos/virtio-scsi.c | 2 +- tests/qtest/libqos/virtio-serial.c | 2 +- tests/qtest/libqos/virtio.c | 2 +- tests/qtest/libqos/x86_64_pc-machine.c | 2 +- tests/qtest/libqtest.c | 2 +- tests/qtest/lpc-ich9-test.c | 2 +- tests/qtest/m48t59-test.c | 2 +- tests/qtest/machine-none-test.c | 2 +- tests/qtest/megasas-test.c | 2 +- tests/qtest/microbit-test.c | 2 +- tests/qtest/migration-test.c | 2 +- tests/qtest/modules-test.c | 2 +- tests/qtest/ne2000-test.c | 2 +- tests/qtest/npcm7xx_adc-test.c | 2 +- tests/qtest/npcm7xx_pwm-test.c | 2 +- tests/qtest/npcm7xx_sdhci-test.c | 2 +- tests/qtest/npcm7xx_smbus-test.c | 2 +- tests/qtest/npcm7xx_watchdog_timer-test.c | 2 +- tests/qtest/numa-test.c | 2 +- tests/qtest/nvme-test.c | 2 +- tests/qtest/pca9552-test.c | 2 +- tests/qtest/pci-test.c | 2 +- tests/qtest/pcnet-test.c | 2 +- tests/qtest/pflash-cfi02-test.c | 2 +- tests/qtest/pnv-xscom-test.c | 2 +- tests/qtest/prom-env-test.c | 2 +- tests/qtest/pvpanic-pci-test.c | 2 +- tests/qtest/pvpanic-test.c | 2 +- tests/qtest/pxe-test.c | 2 +- tests/qtest/q35-test.c | 2 +- tests/qtest/qmp-cmd-test.c | 2 +- tests/qtest/qmp-test.c | 2 +- tests/qtest/qom-test.c | 2 +- tests/qtest/rtas-test.c | 2 +- tests/qtest/sdhci-test.c | 2 +- tests/qtest/spapr-phb-test.c | 2 +- tests/qtest/tco-test.c | 2 +- tests/qtest/test-filter-mirror.c | 2 +- tests/qtest/test-filter-redirector.c | 2 +- tests/qtest/test-hmp.c | 2 +- tests/qtest/tpm-crb-swtpm-test.c | 2 +- tests/qtest/tpm-tis-device-swtpm-test.c | 2 +- tests/qtest/tpm-tis-swtpm-test.c | 2 +- tests/qtest/tpm-util.c | 2 +- tests/qtest/tulip-test.c | 2 +- tests/qtest/virtio-net-failover.c | 2 +- tests/qtest/virtio-rng-test.c | 2 +- tests/qtest/virtio-test.c | 2 +- tests/qtest/vmgenid-test.c | 2 +- tests/qtest/vmxnet3-test.c | 2 +- tests/qtest/wdt_ib700-test.c | 2 +- tests/qtest/xlnx-can-test.c | 2 +- tests/unit/test-qga.c | 2 +- scripts/oss-fuzz/output_reproducer.py | 2 +- 142 files changed, 141 insertions(+), 141 deletions(-) rename tests/qtest/{libqos => }/libqtest.h (100%) diff --git a/docs/devel/qtest.rst b/docs/devel/qtest.rst index XXXXXXX..XXXXXXX 100644 --- a/docs/devel/qtest.rst +++ b/docs/devel/qtest.rst @@ -XXX,XX +XXX,XX @@ QTest Protocol libqtest API reference ---------------------- -.. kernel-doc:: tests/qtest/libqos/libqtest.h +.. kernel-doc:: tests/qtest/libqtest.h diff --git a/tests/qtest/acpi-utils.h b/tests/qtest/acpi-utils.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/acpi-utils.h +++ b/tests/qtest/acpi-utils.h @@ -XXX,XX +XXX,XX @@ #ifndef TEST_ACPI_UTILS_H #define TEST_ACPI_UTILS_H -#include "libqos/libqtest.h" +#include "libqtest.h" /* DSDT and SSDTs format */ typedef struct { diff --git a/tests/qtest/boot-sector.h b/tests/qtest/boot-sector.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/boot-sector.h +++ b/tests/qtest/boot-sector.h @@ -XXX,XX +XXX,XX @@ #ifndef TEST_BOOT_SECTOR_H #define TEST_BOOT_SECTOR_H -#include "libqos/libqtest.h" +#include "libqtest.h" /* Create boot disk file. fname must be a suitable string for mkstemp() */ int boot_sector_init(char *fname); diff --git a/tests/qtest/fuzz/fuzz.h b/tests/qtest/fuzz/fuzz.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/fuzz.h +++ b/tests/qtest/fuzz/fuzz.h @@ -XXX,XX +XXX,XX @@ #include "qemu/units.h" #include "qapi/error.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" /** * A libfuzzer fuzzing target diff --git a/tests/qtest/libqos/fw_cfg.h b/tests/qtest/libqos/fw_cfg.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/fw_cfg.h +++ b/tests/qtest/libqos/fw_cfg.h @@ -XXX,XX +XXX,XX @@ #ifndef LIBQOS_FW_CFG_H #define LIBQOS_FW_CFG_H -#include "libqtest.h" +#include "../libqtest.h" typedef struct QFWCFG QFWCFG; diff --git a/tests/qtest/libqos/i2c.h b/tests/qtest/libqos/i2c.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/i2c.h +++ b/tests/qtest/libqos/i2c.h @@ -XXX,XX +XXX,XX @@ #ifndef LIBQOS_I2C_H #define LIBQOS_I2C_H -#include "libqtest.h" +#include "../libqtest.h" #include "qgraph.h" typedef struct I2CAdapter I2CAdapter; diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/libqos.h +++ b/tests/qtest/libqos/libqos.h @@ -XXX,XX +XXX,XX @@ #ifndef LIBQOS_H #define LIBQOS_H -#include "libqtest.h" +#include "../libqtest.h" #include "pci.h" #include "malloc.h" diff --git a/tests/qtest/libqos/malloc.h b/tests/qtest/libqos/malloc.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/malloc.h +++ b/tests/qtest/libqos/malloc.h @@ -XXX,XX +XXX,XX @@ #define LIBQOS_MALLOC_H #include "qemu/queue.h" -#include "libqtest.h" +#include "../libqtest.h" typedef enum { ALLOC_NO_FLAGS = 0x00, diff --git a/tests/qtest/libqos/pci.h b/tests/qtest/libqos/pci.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/pci.h +++ b/tests/qtest/libqos/pci.h @@ -XXX,XX +XXX,XX @@ #ifndef LIBQOS_PCI_H #define LIBQOS_PCI_H -#include "libqtest.h" +#include "../libqtest.h" #include "qgraph.h" #define QPCI_PIO_LIMIT 0x10000 diff --git a/tests/qtest/libqos/sdhci-cmd.h b/tests/qtest/libqos/sdhci-cmd.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/sdhci-cmd.h +++ b/tests/qtest/libqos/sdhci-cmd.h @@ -XXX,XX +XXX,XX @@ * for more details. */ -#include "libqtest.h" +#include "../libqtest.h" /* more details at hw/sd/sdhci-internal.h */ #define SDHC_BLKSIZE 0x04 diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqtest-single.h +++ b/tests/qtest/libqtest-single.h @@ -XXX,XX +XXX,XX @@ #ifndef LIBQTEST_SINGLE_H #define LIBQTEST_SINGLE_H -#include "libqos/libqtest.h" +#include "libqtest.h" QTestState *global_qtest __attribute__((common, weak)); diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqtest.h similarity index 100% rename from tests/qtest/libqos/libqtest.h rename to tests/qtest/libqtest.h diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -XXX,XX +XXX,XX @@ #ifndef MIGRATION_HELPERS_H_ #define MIGRATION_HELPERS_H_ -#include "libqos/libqtest.h" +#include "libqtest.h" extern bool got_stop; diff --git a/tests/qtest/tpm-emu.h b/tests/qtest/tpm-emu.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tpm-emu.h +++ b/tests/qtest/tpm-emu.h @@ -XXX,XX +XXX,XX @@ #include "qemu/sockets.h" #include "io/channel.h" #include "sysemu/tpm.h" -#include "libqos/libqtest.h" +#include "libqtest.h" struct tpm_hdr { uint16_t tag; diff --git a/tests/qtest/ac97-test.c b/tests/qtest/ac97-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ac97-test.c +++ b/tests/qtest/ac97-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <getopt.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/libqos-pc.h" #include "libqos/ahci.h" #include "libqos/pci-pc.h" diff --git a/tests/qtest/am53c974-test.c b/tests/qtest/am53c974-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/am53c974-test.c +++ b/tests/qtest/am53c974-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" static void test_cmdfifo_underflow_ok(void) diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/arm-cpu-features.c +++ b/tests/qtest/arm-cpu-features.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" #include "qemu/bitops.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" diff --git a/tests/qtest/aspeed_hace-test.c b/tests/qtest/aspeed_hace-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/aspeed_hace-test.c +++ b/tests/qtest/aspeed_hace-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/bitops.h" #define HACE_CMD 0x10 diff --git a/tests/qtest/boot-order-test.c b/tests/qtest/boot-order-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/boot-order-test.c +++ b/tests/qtest/boot-order-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "libqos/fw_cfg.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "standard-headers/linux/qemu_fw_cfg.h" diff --git a/tests/qtest/boot-sector.c b/tests/qtest/boot-sector.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/boot-sector.c +++ b/tests/qtest/boot-sector.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" #include "boot-sector.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #define LOW(x) ((x) & 0xff) #define HIGH(x) ((x) >> 8) diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/boot-serial-test.c +++ b/tests/qtest/boot-serial-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/libqos-spapr.h" static const uint8_t bios_avr[] = { diff --git a/tests/qtest/cdrom-test.c b/tests/qtest/cdrom-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/cdrom-test.c +++ b/tests/qtest/cdrom-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "boot-sector.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/dbus-display-test.c b/tests/qtest/dbus-display-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/dbus-display-test.c +++ b/tests/qtest/dbus-display-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/dbus.h" #include <gio/gio.h> #include <gio/gunixfdlist.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "dbus-display1.h" static GDBusConnection* diff --git a/tests/qtest/dbus-vmstate-test.c b/tests/qtest/dbus-vmstate-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/dbus-vmstate-test.c +++ b/tests/qtest/dbus-vmstate-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> #include <gio/gio.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "dbus-vmstate1.h" #include "migration-helpers.h" diff --git a/tests/qtest/device-introspect-test.c b/tests/qtest/device-introspect-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/device-introspect-test.c +++ b/tests/qtest/device-introspect-test.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qmp/qstring.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" -#include "libqos/libqtest.h" +#include "libqtest.h" const char common_args[] = "-nodefaults -machine none"; diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/device-plug-test.c +++ b/tests/qtest/device-plug-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/drive_del-test.c +++ b/tests/qtest/drive_del-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/virtio.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ds1338-test.c +++ b/tests/qtest/ds1338-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/i2c.h" #define DS1338_ADDR 0x68 diff --git a/tests/qtest/e1000-test.c b/tests/qtest/e1000-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/e1000-test.c +++ b/tests/qtest/e1000-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/eepro100-test.c b/tests/qtest/eepro100-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/eepro100-test.c +++ b/tests/qtest/eepro100-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/endianness-test.c b/tests/qtest/endianness-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/endianness-test.c +++ b/tests/qtest/endianness-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/bswap.h" typedef struct TestCase TestCase; diff --git a/tests/qtest/erst-test.c b/tests/qtest/erst-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/erst-test.c +++ b/tests/qtest/erst-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> #include "libqos/libqos-pc.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "hw/pci/pci.h" diff --git a/tests/qtest/es1370-test.c b/tests/qtest/es1370-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/es1370-test.c +++ b/tests/qtest/es1370-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/fuzz-e1000e-test.c b/tests/qtest/fuzz-e1000e-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-e1000e-test.c +++ b/tests/qtest/fuzz-e1000e-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * https://bugs.launchpad.net/qemu/+bug/1879531 diff --git a/tests/qtest/fuzz-lsi53c895a-test.c b/tests/qtest/fuzz-lsi53c895a-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-lsi53c895a-test.c +++ b/tests/qtest/fuzz-lsi53c895a-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * This used to trigger the assert in lsi_do_dma() diff --git a/tests/qtest/fuzz-megasas-test.c b/tests/qtest/fuzz-megasas-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-megasas-test.c +++ b/tests/qtest/fuzz-megasas-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * This used to trigger the assert in scsi_dma_complete diff --git a/tests/qtest/fuzz-sb16-test.c b/tests/qtest/fuzz-sb16-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-sb16-test.c +++ b/tests/qtest/fuzz-sb16-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * This used to trigger the assert in audio_calloc diff --git a/tests/qtest/fuzz-sdcard-test.c b/tests/qtest/fuzz-sdcard-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-sdcard-test.c +++ b/tests/qtest/fuzz-sdcard-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * https://gitlab.com/qemu-project/qemu/-/issues/450 diff --git a/tests/qtest/fuzz-virtio-scsi-test.c b/tests/qtest/fuzz-virtio-scsi-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-virtio-scsi-test.c +++ b/tests/qtest/fuzz-virtio-scsi-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * Here a MemoryRegionCache pointed to an MMIO region but had a diff --git a/tests/qtest/fuzz-xlnx-dp-test.c b/tests/qtest/fuzz-xlnx-dp-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz-xlnx-dp-test.c +++ b/tests/qtest/fuzz-xlnx-dp-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * This used to trigger the out-of-bounds read in xlnx_dp_read diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -XXX,XX +XXX,XX @@ #include "sysemu/runstate.h" #include "qemu/main-loop.h" #include "qemu/rcu.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/qgraph.h" #include "fuzz.h" diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/generic_fuzz.c +++ b/tests/qtest/fuzz/generic_fuzz.c @@ -XXX,XX +XXX,XX @@ #include <wordexp.h> #include "hw/core/cpu.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/pci-pc.h" #include "fuzz.h" #include "fork_fuzz.h" diff --git a/tests/qtest/fuzz/i440fx_fuzz.c b/tests/qtest/fuzz/i440fx_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/i440fx_fuzz.c +++ b/tests/qtest/fuzz/i440fx_fuzz.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/pci.h" #include "tests/qtest/libqos/pci-pc.h" #include "fuzz.h" diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/qos_fuzz.c +++ b/tests/qtest/fuzz/qos_fuzz.c @@ -XXX,XX +XXX,XX @@ #include "exec/memory.h" #include "qemu/main-loop.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/malloc.h" #include "tests/qtest/libqos/qgraph.h" #include "tests/qtest/libqos/qgraph_internal.h" diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c b/tests/qtest/fuzz/virtio_blk_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/virtio_blk_fuzz.c +++ b/tests/qtest/fuzz/virtio_blk_fuzz.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/virtio-blk.h" #include "tests/qtest/libqos/virtio.h" #include "tests/qtest/libqos/virtio-pci.h" diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_net_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/virtio_net_fuzz.c +++ b/tests/qtest/fuzz/virtio_net_fuzz.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "standard-headers/linux/virtio_config.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/virtio-net.h" #include "fuzz.h" #include "fork_fuzz.h" diff --git a/tests/qtest/fuzz/virtio_scsi_fuzz.c b/tests/qtest/fuzz/virtio_scsi_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/virtio_scsi_fuzz.c +++ b/tests/qtest/fuzz/virtio_scsi_fuzz.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "tests/qtest/libqos/libqtest.h" +#include "tests/qtest/libqtest.h" #include "tests/qtest/libqos/virtio-scsi.h" #include "tests/qtest/libqos/virtio.h" #include "tests/qtest/libqos/virtio-pci.h" diff --git a/tests/qtest/fw_cfg-test.c b/tests/qtest/fw_cfg-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fw_cfg-test.c +++ b/tests/qtest/fw_cfg-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "standard-headers/linux/qemu_fw_cfg.h" #include "libqos/fw_cfg.h" #include "qemu/bswap.h" diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/hd-geo-test.c +++ b/tests/qtest/hd-geo-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/bswap.h" #include "qapi/qmp/qlist.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/fw_cfg.h" #include "libqos/libqos.h" #include "standard-headers/linux/qemu_fw_cfg.h" diff --git a/tests/qtest/hexloader-test.c b/tests/qtest/hexloader-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/hexloader-test.c +++ b/tests/qtest/hexloader-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* Load 'test.hex' and verify that the in-memory contents are as expected. * 'test.hex' is a memory test pattern stored in Hexadecimal Object diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ide-test.c +++ b/tests/qtest/ide-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/libqos.h" #include "libqos/pci-pc.h" #include "libqos/malloc-pc.h" diff --git a/tests/qtest/ipoctal232-test.c b/tests/qtest/ipoctal232-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ipoctal232-test.c +++ b/tests/qtest/ipoctal232-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ivshmem-test.c +++ b/tests/qtest/ivshmem-test.c @@ -XXX,XX +XXX,XX @@ #include "contrib/ivshmem-server/ivshmem-server.h" #include "libqos/libqos-pc.h" #include "libqos/libqos-spapr.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #define TMPSHMSIZE (1 << 20) static char *tmpshm; diff --git a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c +++ b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "ahci.h" #include "pci-pc.h" diff --git a/tests/qtest/libqos/arm-imx25-pdk-machine.c b/tests/qtest/libqos/arm-imx25-pdk-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-imx25-pdk-machine.c +++ b/tests/qtest/libqos/arm-imx25-pdk-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "malloc.h" #include "qgraph.h" #include "i2c.h" diff --git a/tests/qtest/libqos/arm-n800-machine.c b/tests/qtest/libqos/arm-n800-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-n800-machine.c +++ b/tests/qtest/libqos/arm-n800-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "malloc.h" #include "qgraph.h" #include "i2c.h" diff --git a/tests/qtest/libqos/arm-raspi2-machine.c b/tests/qtest/libqos/arm-raspi2-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-raspi2-machine.c +++ b/tests/qtest/libqos/arm-raspi2-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/arm-sabrelite-machine.c b/tests/qtest/libqos/arm-sabrelite-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-sabrelite-machine.c +++ b/tests/qtest/libqos/arm-sabrelite-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/arm-smdkc210-machine.c b/tests/qtest/libqos/arm-smdkc210-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-smdkc210-machine.c +++ b/tests/qtest/libqos/arm-smdkc210-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/arm-virt-machine.c b/tests/qtest/libqos/arm-virt-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-virt-machine.c +++ b/tests/qtest/libqos/arm-virt-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c +++ b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "malloc.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/e1000e.c b/tests/qtest/libqos/e1000e.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/e1000e.c +++ b/tests/qtest/libqos/e1000e.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "pci-pc.h" #include "qemu/sockets.h" #include "qemu/iov.h" diff --git a/tests/qtest/libqos/fw_cfg.c b/tests/qtest/libqos/fw_cfg.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/fw_cfg.c +++ b/tests/qtest/libqos/fw_cfg.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "fw_cfg.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/bswap.h" #include "hw/nvram/fw_cfg.h" diff --git a/tests/qtest/libqos/i2c-imx.c b/tests/qtest/libqos/i2c-imx.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/i2c-imx.c +++ b/tests/qtest/libqos/i2c-imx.c @@ -XXX,XX +XXX,XX @@ #include "i2c.h" -#include "libqtest.h" +#include "../libqtest.h" #include "hw/i2c/imx_i2c.h" diff --git a/tests/qtest/libqos/i2c-omap.c b/tests/qtest/libqos/i2c-omap.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/i2c-omap.c +++ b/tests/qtest/libqos/i2c-omap.c @@ -XXX,XX +XXX,XX @@ #include "qemu/bswap.h" -#include "libqtest.h" +#include "../libqtest.h" enum OMAPI2CRegisters { OMAP_I2C_REV = 0x00, diff --git a/tests/qtest/libqos/i2c.c b/tests/qtest/libqos/i2c.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/i2c.c +++ b/tests/qtest/libqos/i2c.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" #include "i2c.h" -#include "libqtest.h" +#include "../libqtest.h" void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len) { diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/libqos.c +++ b/tests/qtest/libqos/libqos.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <sys/wait.h> -#include "libqtest.h" +#include "../libqtest.h" #include "libqos.h" #include "pci.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/libqos/pci-pc.c b/tests/qtest/libqos/pci-pc.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/pci-pc.c +++ b/tests/qtest/libqos/pci-pc.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "pci-pc.h" #include "qapi/qmp/qdict.h" #include "hw/pci/pci_regs.h" diff --git a/tests/qtest/libqos/pci-spapr.c b/tests/qtest/libqos/pci-spapr.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/pci-spapr.c +++ b/tests/qtest/libqos/pci-spapr.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "pci-spapr.h" #include "rtas.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/ppc64_pseries-machine.c b/tests/qtest/libqos/ppc64_pseries-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/ppc64_pseries-machine.c +++ b/tests/qtest/libqos/ppc64_pseries-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qgraph.h" #include "pci-spapr.h" #include "qemu/module.h" diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/qgraph.c +++ b/tests/qtest/libqos/qgraph.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/queue.h" #include "qgraph_internal.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/qos_external.c b/tests/qtest/libqos/qos_external.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/qos_external.c +++ b/tests/qtest/libqos/qos_external.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <getopt.h> -#include "libqtest.h" +#include "../libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qstring.h" diff --git a/tests/qtest/libqos/rtas.c b/tests/qtest/libqos/rtas.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/rtas.c +++ b/tests/qtest/libqos/rtas.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "rtas.h" static void qrtas_copy_args(QTestState *qts, uint64_t target_args, diff --git a/tests/qtest/libqos/sdhci-cmd.c b/tests/qtest/libqos/sdhci-cmd.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/sdhci-cmd.c +++ b/tests/qtest/libqos/sdhci-cmd.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "sdhci-cmd.h" -#include "libqtest.h" +#include "../libqtest.h" static ssize_t read_fifo(QTestState *qts, uint64_t reg, char *msg, size_t count) { diff --git a/tests/qtest/libqos/sdhci.c b/tests/qtest/libqos/sdhci.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/sdhci.c +++ b/tests/qtest/libqos/sdhci.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qgraph.h" #include "pci.h" #include "qemu/module.h" diff --git a/tests/qtest/libqos/tpci200.c b/tests/qtest/libqos/tpci200.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/tpci200.c +++ b/tests/qtest/libqos/tpci200.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "pci.h" diff --git a/tests/qtest/libqos/usb.c b/tests/qtest/libqos/usb.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/usb.c +++ b/tests/qtest/libqos/usb.c @@ -XXX,XX +XXX,XX @@ * See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "hw/usb/uhci-regs.h" #include "usb.h" diff --git a/tests/qtest/libqos/vhost-user-blk.c b/tests/qtest/libqos/vhost-user-blk.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/vhost-user-blk.c +++ b/tests/qtest/libqos/vhost-user-blk.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "standard-headers/linux/virtio_blk.h" #include "vhost-user-blk.h" diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "standard-headers/linux/virtio_ids.h" #include "virtio-9p.h" diff --git a/tests/qtest/libqos/virtio-balloon.c b/tests/qtest/libqos/virtio-balloon.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-balloon.c +++ b/tests/qtest/libqos/virtio-balloon.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "virtio-balloon.h" diff --git a/tests/qtest/libqos/virtio-blk.c b/tests/qtest/libqos/virtio-blk.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-blk.c +++ b/tests/qtest/libqos/virtio-blk.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "standard-headers/linux/virtio_blk.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/virtio-iommu.c b/tests/qtest/libqos/virtio-iommu.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-iommu.c +++ b/tests/qtest/libqos/virtio-iommu.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "virtio-iommu.h" diff --git a/tests/qtest/libqos/virtio-mmio.c b/tests/qtest/libqos/virtio-mmio.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-mmio.c +++ b/tests/qtest/libqos/virtio-mmio.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "virtio.h" #include "virtio-mmio.h" diff --git a/tests/qtest/libqos/virtio-net.c b/tests/qtest/libqos/virtio-net.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-net.c +++ b/tests/qtest/libqos/virtio-net.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "virtio-net.h" diff --git a/tests/qtest/libqos/virtio-pci.c b/tests/qtest/libqos/virtio-pci.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-pci.c +++ b/tests/qtest/libqos/virtio-pci.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "virtio.h" #include "virtio-pci.h" #include "pci.h" diff --git a/tests/qtest/libqos/virtio-rng.c b/tests/qtest/libqos/virtio-rng.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-rng.c +++ b/tests/qtest/libqos/virtio-rng.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "virtio-rng.h" diff --git a/tests/qtest/libqos/virtio-scsi.c b/tests/qtest/libqos/virtio-scsi.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-scsi.c +++ b/tests/qtest/libqos/virtio-scsi.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "standard-headers/linux/virtio_ids.h" #include "qgraph.h" diff --git a/tests/qtest/libqos/virtio-serial.c b/tests/qtest/libqos/virtio-serial.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio-serial.c +++ b/tests/qtest/libqos/virtio-serial.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qemu/module.h" #include "qgraph.h" #include "virtio-serial.h" diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/virtio.c +++ b/tests/qtest/libqos/virtio.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/bswap.h" -#include "libqtest.h" +#include "../libqtest.h" #include "virtio.h" #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" diff --git a/tests/qtest/libqos/x86_64_pc-machine.c b/tests/qtest/libqos/x86_64_pc-machine.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/x86_64_pc-machine.c +++ b/tests/qtest/libqos/x86_64_pc-machine.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqtest.h" +#include "../libqtest.h" #include "qgraph.h" #include "pci-pc.h" #include "qemu/module.h" diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -XXX,XX +XXX,XX @@ #include <sys/wait.h> #include <sys/un.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/ctype.h" #include "qemu/cutils.h" #include "qapi/error.h" diff --git a/tests/qtest/lpc-ich9-test.c b/tests/qtest/lpc-ich9-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/lpc-ich9-test.c +++ b/tests/qtest/lpc-ich9-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" static void test_lp1878642_pci_bus_get_irq_level_assert(void) { diff --git a/tests/qtest/m48t59-test.c b/tests/qtest/m48t59-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/m48t59-test.c +++ b/tests/qtest/m48t59-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #define RTC_SECONDS 0x9 #define RTC_MINUTES 0xa diff --git a/tests/qtest/machine-none-test.c b/tests/qtest/machine-none-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/machine-none-test.c +++ b/tests/qtest/machine-none-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/megasas-test.c b/tests/qtest/megasas-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/megasas-test.c +++ b/tests/qtest/megasas-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/bswap.h" #include "qemu/module.h" #include "libqos/qgraph.h" diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/microbit-test.c +++ b/tests/qtest/microbit-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "exec/hwaddr.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "hw/arm/nrf51.h" #include "hw/char/nrf51_uart.h" diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qemu/module.h" diff --git a/tests/qtest/modules-test.c b/tests/qtest/modules-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/modules-test.c +++ b/tests/qtest/modules-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" const char common_args[] = "-nodefaults -machine none"; diff --git a/tests/qtest/ne2000-test.c b/tests/qtest/ne2000-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ne2000-test.c +++ b/tests/qtest/ne2000-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/npcm7xx_adc-test.c +++ b/tests/qtest/npcm7xx_adc-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/bitops.h" #include "qemu/timer.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #define REF_HZ (25000000) diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/npcm7xx_pwm-test.c +++ b/tests/qtest/npcm7xx_pwm-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/bitops.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qnum.h" diff --git a/tests/qtest/npcm7xx_sdhci-test.c b/tests/qtest/npcm7xx_sdhci-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/npcm7xx_sdhci-test.c +++ b/tests/qtest/npcm7xx_sdhci-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/sd/npcm7xx_sdhci.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqtest-single.h" #include "libqos/sdhci-cmd.h" diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/npcm7xx_smbus-test.c +++ b/tests/qtest/npcm7xx_smbus-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/bitops.h" #include "libqos/i2c.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "hw/sensor/tmp105_regs.h" #define NR_SMBUS_DEVICES 16 diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/npcm7xx_watchdog_timer-test.c +++ b/tests/qtest/npcm7xx_watchdog_timer-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/timer.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #define WTCR_OFFSET 0x1c diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/numa-test.c +++ b/tests/qtest/numa-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" diff --git a/tests/qtest/nvme-test.c b/tests/qtest/nvme-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/nvme-test.c +++ b/tests/qtest/nvme-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/module.h" #include "qemu/units.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/qgraph.h" #include "libqos/pci.h" #include "include/block/nvme.h" diff --git a/tests/qtest/pca9552-test.c b/tests/qtest/pca9552-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pca9552-test.c +++ b/tests/qtest/pca9552-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/qgraph.h" #include "libqos/i2c.h" #include "hw/misc/pca9552_regs.h" diff --git a/tests/qtest/pci-test.c b/tests/qtest/pci-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pci-test.c +++ b/tests/qtest/pci-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/pcnet-test.c b/tests/qtest/pcnet-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pcnet-test.c +++ b/tests/qtest/pcnet-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pflash-cfi02-test.c +++ b/tests/qtest/pflash-cfi02-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* * To test the pflash_cfi02 device, we run QEMU with the musicpal machine with diff --git a/tests/qtest/pnv-xscom-test.c b/tests/qtest/pnv-xscom-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pnv-xscom-test.c +++ b/tests/qtest/pnv-xscom-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" typedef enum PnvChipType { PNV_CHIP_POWER8E, /* AKA Murano (default) */ diff --git a/tests/qtest/prom-env-test.c b/tests/qtest/prom-env-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/prom-env-test.c +++ b/tests/qtest/prom-env-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/libqos-spapr.h" #define MAGIC 0xcafec0de diff --git a/tests/qtest/pvpanic-pci-test.c b/tests/qtest/pvpanic-pci-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pvpanic-pci-test.c +++ b/tests/qtest/pvpanic-pci-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pvpanic-test.c +++ b/tests/qtest/pvpanic-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" static void test_panic_nopause(void) diff --git a/tests/qtest/pxe-test.c b/tests/qtest/pxe-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/pxe-test.c +++ b/tests/qtest/pxe-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "boot-sector.h" #include "libqos/libqos-spapr.h" diff --git a/tests/qtest/q35-test.c b/tests/qtest/q35-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/q35-test.c +++ b/tests/qtest/q35-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" #include "hw/pci-host/q35.h" diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/error.h" #include "qapi/qapi-visit-introspect.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/qmp-test.c +++ b/tests/qtest/qmp-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/error.h" #include "qapi/qapi-visit-control.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/qom-test.c +++ b/tests/qtest/qom-test.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/cutils.h" -#include "libqos/libqtest.h" +#include "libqtest.h" static void test_properties(QTestState *qts, const char *path, bool recurse) { diff --git a/tests/qtest/rtas-test.c b/tests/qtest/rtas-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/rtas-test.c +++ b/tests/qtest/rtas-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/libqos-spapr.h" #include "libqos/rtas.h" diff --git a/tests/qtest/sdhci-test.c b/tests/qtest/sdhci-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/sdhci-test.c +++ b/tests/qtest/sdhci-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/registerfields.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/pci-pc.h" #include "hw/pci/pci.h" diff --git a/tests/qtest/spapr-phb-test.c b/tests/qtest/spapr-phb-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/spapr-phb-test.c +++ b/tests/qtest/spapr-phb-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" diff --git a/tests/qtest/tco-test.c b/tests/qtest/tco-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tco-test.c +++ b/tests/qtest/tco-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/test-filter-mirror.c +++ b/tests/qtest/test-filter-mirror.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qemu/iov.h" #include "qemu/sockets.h" diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qemu/iov.h" #include "qemu/sockets.h" diff --git a/tests/qtest/test-hmp.c b/tests/qtest/test-hmp.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/test-hmp.c +++ b/tests/qtest/test-hmp.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" static int verbose; diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tpm-crb-swtpm-test.c +++ b/tests/qtest/tpm-crb-swtpm-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" #include "hw/acpi/tpm.h" diff --git a/tests/qtest/tpm-tis-device-swtpm-test.c b/tests/qtest/tpm-tis-device-swtpm-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tpm-tis-device-swtpm-test.c +++ b/tests/qtest/tpm-tis-device-swtpm-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" #include "hw/acpi/tpm.h" diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tpm-tis-swtpm-test.c +++ b/tests/qtest/tpm-tis-swtpm-test.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include <glib/gstdio.h> -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" #include "hw/acpi/tpm.h" diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tpm-util.c +++ b/tests/qtest/tpm-util.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" #include "hw/acpi/tpm.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "tpm-util.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/tulip-test.c b/tests/qtest/tulip-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/tulip-test.c +++ b/tests/qtest/tulip-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/virtio-net-failover.c +++ b/tests/qtest/virtio-net-failover.c @@ -XXX,XX +XXX,XX @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "libqos/pci.h" #include "libqos/pci-pc.h" #include "qapi/qmp/qdict.h" diff --git a/tests/qtest/virtio-rng-test.c b/tests/qtest/virtio-rng-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/virtio-rng-test.c +++ b/tests/qtest/virtio-rng-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/virtio-rng.h" diff --git a/tests/qtest/virtio-test.c b/tests/qtest/virtio-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/virtio-test.c +++ b/tests/qtest/virtio-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/vmgenid-test.c b/tests/qtest/vmgenid-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/vmgenid-test.c +++ b/tests/qtest/vmgenid-test.c @@ -XXX,XX +XXX,XX @@ #include "hw/acpi/acpi-defs.h" #include "boot-sector.h" #include "acpi-utils.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #define VGID_GUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" diff --git a/tests/qtest/vmxnet3-test.c b/tests/qtest/vmxnet3-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/vmxnet3-test.c +++ b/tests/qtest/vmxnet3-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qemu/module.h" #include "libqos/qgraph.h" #include "libqos/pci.h" diff --git a/tests/qtest/wdt_ib700-test.c b/tests/qtest/wdt_ib700-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/wdt_ib700-test.c +++ b/tests/qtest/wdt_ib700-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" #include "qapi/qmp/qdict.h" #include "qemu/timer.h" diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/xlnx-can-test.c +++ b/tests/qtest/xlnx-can-test.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" /* Base address. */ #define CAN0_BASE_ADDR 0xFF060000 diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -XXX,XX +XXX,XX @@ #include <sys/socket.h> #include <sys/un.h> -#include "../qtest/libqos/libqtest.h" +#include "../qtest/libqtest.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" diff --git a/scripts/oss-fuzz/output_reproducer.py b/scripts/oss-fuzz/output_reproducer.py index XXXXXXX..XXXXXXX 100755 --- a/scripts/oss-fuzz/output_reproducer.py +++ b/scripts/oss-fuzz/output_reproducer.py @@ -XXX,XX +XXX,XX @@ def c_header(owner): #include "qemu/osdep.h" -#include "libqos/libqtest.h" +#include "libqtest.h" """.format(date=date.today().year, owner=owner) -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> This will help moving QAPI/QMP in a common subproject. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Thomas Huth <thuth@redhat.com> --- tests/qtest/libqmp.h | 50 +++++++ tests/qtest/libqtest.h | 29 +--- tests/qtest/libqmp.c | 233 +++++++++++++++++++++++++++++++++ tests/qtest/libqtest.c | 205 +---------------------------- tests/qtest/libqos/meson.build | 5 +- tests/unit/meson.build | 2 +- 6 files changed, 290 insertions(+), 234 deletions(-) create mode 100644 tests/qtest/libqmp.h create mode 100644 tests/qtest/libqmp.c diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/tests/qtest/libqmp.h @@ -XXX,XX +XXX,XX @@ +/* + * libqmp test unit + * + * Copyright IBM, Corp. 2012 + * Copyright Red Hat, Inc. 2012 + * Copyright SUSE LINUX Products GmbH 2013 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * Paolo Bonzini <pbonzini@redhat.com> + * Andreas Färber <afaerber@suse.de> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ +#ifndef LIBQMP_H_ +#define LIBQMP_H_ + +#include "qapi/qmp/qdict.h" + +QDict *qmp_fd_receive(int fd); +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0); +void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); +void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); +void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); +void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); +QDict *qmp_fdv(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); +QDict *qmp_fd(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); + +/** + * qmp_rsp_is_err: + * @rsp: QMP response to check for error + * + * Test @rsp for error and discard @rsp. + * Returns 'true' if there is error in @rsp and 'false' otherwise. + */ +bool qmp_rsp_is_err(QDict *rsp); + +/** + * qmp_expect_error_and_unref: + * @rsp: QMP response to check for error + * @class: an error class + * + * Assert the response has the given error class and discard @rsp. + */ +void qmp_expect_error_and_unref(QDict *rsp, const char *class); + +#endif /* LIBQMP_H_ */ diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -XXX,XX +XXX,XX @@ #include "qapi/qmp/qobject.h" #include "qapi/qmp/qdict.h" +#include "libqmp.h" typedef struct QTestState QTestState; @@ -XXX,XX +XXX,XX @@ void qtest_remove_abrt_handler(void *data); void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -QDict *qmp_fd_receive(int fd); -void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, - const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0); -void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); -void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); -QDict *qmp_fdv(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); -QDict *qmp_fd(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); - /** * qtest_cb_for_every_machine: * @cb: Pointer to the callback function @@ -XXX,XX +XXX,XX @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd); */ void qtest_qmp_device_del(QTestState *qts, const char *id); -/** - * qmp_rsp_is_err: - * @rsp: QMP response to check for error - * - * Test @rsp for error and discard @rsp. - * Returns 'true' if there is error in @rsp and 'false' otherwise. - */ -bool qmp_rsp_is_err(QDict *rsp); - -/** - * qmp_expect_error_and_unref: - * @rsp: QMP response to check for error - * @class: an error class - * - * Assert the response has the given error class and discard @rsp. - */ -void qmp_expect_error_and_unref(QDict *rsp, const char *class); - /** * qtest_probe_child: * @s: QTestState instance to operate on. diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/tests/qtest/libqmp.c @@ -XXX,XX +XXX,XX @@ +/* + * QTest + * + * Copyright IBM, Corp. 2012 + * Copyright Red Hat, Inc. 2012 + * Copyright SUSE LINUX Products GmbH 2013 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * Paolo Bonzini <pbonzini@redhat.com> + * Andreas Färber <afaerber@suse.de> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "libqmp.h" + +#include "qapi/error.h" +#include "qapi/qmp/json-parser.h" +#include "qapi/qmp/qjson.h" + +#define SOCKET_MAX_FDS 16 + +typedef struct { + JSONMessageParser parser; + QDict *response; +} QMPResponseParser; + +static void socket_send(int fd, const char *buf, size_t size) +{ + size_t res = qemu_write_full(fd, buf, size); + + assert(res == size); +} + +static void qmp_response(void *opaque, QObject *obj, Error *err) +{ + QMPResponseParser *qmp = opaque; + + assert(!obj != !err); + + if (err) { + error_prepend(&err, "QMP JSON response parsing failed: "); + error_report_err(err); + abort(); + } + + g_assert(!qmp->response); + qmp->response = qobject_to(QDict, obj); + g_assert(qmp->response); +} + +QDict *qmp_fd_receive(int fd) +{ + QMPResponseParser qmp; + bool log = getenv("QTEST_LOG") != NULL; + + qmp.response = NULL; + json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL); + while (!qmp.response) { + ssize_t len; + char c; + + len = read(fd, &c, 1); + if (len == -1 && errno == EINTR) { + continue; + } + + if (len == -1 || len == 0) { + fprintf(stderr, "Broken pipe\n"); + abort(); + } + + if (log) { + g_assert(write(2, &c, 1) == 1); + } + json_message_parser_feed(&qmp.parser, &c, 1); + } + if (log) { + g_assert(write(2, "\n", 1) == 1); + } + json_message_parser_destroy(&qmp.parser); + + return qmp.response; +} + +/* Sends a message and file descriptors to the socket. + * It's needed for qmp-commands like getfd/add-fd */ +static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, + const char *buf, size_t buf_size) +{ + ssize_t ret; + struct msghdr msg = { 0 }; + char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; + size_t fdsize = sizeof(int) * fds_num; + struct cmsghdr *cmsg; + struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size }; + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + if (fds && fds_num > 0) { + g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS); + + msg.msg_control = control; + msg.msg_controllen = CMSG_SPACE(fdsize); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(fdsize); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + memcpy(CMSG_DATA(cmsg), fds, fdsize); + } + + do { + ret = sendmsg(socket_fd, &msg, 0); + } while (ret < 0 && errno == EINTR); + g_assert_cmpint(ret, >, 0); +} + +/** + * Allow users to send a message without waiting for the reply, + * in the case that they choose to discard all replies up until + * a particular EVENT is received. + */ +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + QObject *qobj; + + /* Going through qobject ensures we escape strings properly */ + qobj = qobject_from_vjsonf_nofail(fmt, ap); + + /* No need to send anything for an empty QObject. */ + if (qobj) { + int log = getenv("QTEST_LOG") != NULL; + GString *str = qobject_to_json(qobj); + + /* + * BUG: QMP doesn't react to input until it sees a newline, an + * object, or an array. Work-around: give it a newline. + */ + g_string_append_c(str, '\n'); + + if (log) { + fprintf(stderr, "%s", str->str); + } + /* Send QMP request */ + if (fds && fds_num > 0) { + socket_send_fds(fd, fds, fds_num, str->str, str->len); + } else { + socket_send(fd, str->str, str->len); + } + + g_string_free(str, true); + qobject_unref(qobj); + } +} + +void qmp_fd_vsend(int fd, const char *fmt, va_list ap) +{ + qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); +} + + +QDict *qmp_fdv(int fd, const char *fmt, va_list ap) +{ + qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + + return qmp_fd_receive(fd); +} + +QDict *qmp_fd(int fd, const char *fmt, ...) +{ + va_list ap; + QDict *response; + + va_start(ap, fmt); + response = qmp_fdv(fd, fmt, ap); + va_end(ap); + return response; +} + +void qmp_fd_send(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qmp_fd_vsend(fd, fmt, ap); + va_end(ap); +} + +void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) +{ + bool log = getenv("QTEST_LOG") != NULL; + char *str = g_strdup_vprintf(fmt, ap); + + if (log) { + fprintf(stderr, "%s", str); + } + socket_send(fd, str, strlen(str)); + g_free(str); +} + +void qmp_fd_send_raw(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + qmp_fd_vsend_raw(fd, fmt, ap); + va_end(ap); +} + +bool qmp_rsp_is_err(QDict *rsp) +{ + QDict *error = qdict_get_qdict(rsp, "error"); + qobject_unref(rsp); + return !!error; +} + +void qmp_expect_error_and_unref(QDict *rsp, const char *class) +{ + QDict *error = qdict_get_qdict(rsp, "error"); + + g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class); + g_assert_nonnull(qdict_get_try_str(error, "desc")); + g_assert(!qdict_haskey(rsp, "return")); + + qobject_unref(rsp); +} diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -XXX,XX +XXX,XX @@ #include <sys/un.h> #include "libqtest.h" +#include "libqmp.h" #include "qemu/ctype.h" #include "qemu/cutils.h" -#include "qapi/error.h" -#include "qapi/qmp/json-parser.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" @@ -XXX,XX +XXX,XX @@ #define MAX_IRQ 256 #define SOCKET_TIMEOUT 50 -#define SOCKET_MAX_FDS 16 - typedef void (*QTestSendFn)(QTestState *s, const char *buf); typedef void (*ExternalSendFn)(void *s, const char *buf); @@ -XXX,XX +XXX,XX @@ static void G_GNUC_PRINTF(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) g_free(str); } -/* Sends a message and file descriptors to the socket. - * It's needed for qmp-commands like getfd/add-fd */ -static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, - const char *buf, size_t buf_size) -{ - ssize_t ret; - struct msghdr msg = { 0 }; - char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; - size_t fdsize = sizeof(int) * fds_num; - struct cmsghdr *cmsg; - struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size }; - - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - if (fds && fds_num > 0) { - g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS); - - msg.msg_control = control; - msg.msg_controllen = CMSG_SPACE(fdsize); - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = CMSG_LEN(fdsize); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmsg), fds, fdsize); - } - - do { - ret = sendmsg(socket_fd, &msg, 0); - } while (ret < 0 && errno == EINTR); - g_assert_cmpint(ret, >, 0); -} - static GString *qtest_client_socket_recv_line(QTestState *s) { GString *line; @@ -XXX,XX +XXX,XX @@ static int qtest_query_target_endianness(QTestState *s) return big_endian; } -typedef struct { - JSONMessageParser parser; - QDict *response; -} QMPResponseParser; - -static void qmp_response(void *opaque, QObject *obj, Error *err) -{ - QMPResponseParser *qmp = opaque; - - assert(!obj != !err); - - if (err) { - error_prepend(&err, "QMP JSON response parsing failed: "); - error_report_err(err); - abort(); - } - - g_assert(!qmp->response); - qmp->response = qobject_to(QDict, obj); - g_assert(qmp->response); -} - -QDict *qmp_fd_receive(int fd) -{ - QMPResponseParser qmp; - bool log = getenv("QTEST_LOG") != NULL; - - qmp.response = NULL; - json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL); - while (!qmp.response) { - ssize_t len; - char c; - - len = read(fd, &c, 1); - if (len == -1 && errno == EINTR) { - continue; - } - - if (len == -1 || len == 0) { - fprintf(stderr, "Broken pipe\n"); - abort(); - } - - if (log) { - g_assert(write(2, &c, 1) == 1); - } - json_message_parser_feed(&qmp.parser, &c, 1); - } - if (log) { - g_assert(write(2, "\n", 1) == 1); - } - json_message_parser_destroy(&qmp.parser); - - return qmp.response; -} - QDict *qtest_qmp_receive(QTestState *s) { while (true) { @@ -XXX,XX +XXX,XX @@ int qtest_socket_server(const char *socket_path) return sock; } -/** - * Allow users to send a message without waiting for the reply, - * in the case that they choose to discard all replies up until - * a particular EVENT is received. - */ -void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, - const char *fmt, va_list ap) -{ - QObject *qobj; - - /* Going through qobject ensures we escape strings properly */ - qobj = qobject_from_vjsonf_nofail(fmt, ap); - - /* No need to send anything for an empty QObject. */ - if (qobj) { - int log = getenv("QTEST_LOG") != NULL; - GString *str = qobject_to_json(qobj); - - /* - * BUG: QMP doesn't react to input until it sees a newline, an - * object, or an array. Work-around: give it a newline. - */ - g_string_append_c(str, '\n'); - - if (log) { - fprintf(stderr, "%s", str->str); - } - /* Send QMP request */ - if (fds && fds_num > 0) { - socket_send_fds(fd, fds, fds_num, str->str, str->len); - } else { - socket_send(fd, str->str, str->len); - } - - g_string_free(str, true); - qobject_unref(qobj); - } -} - -void qmp_fd_vsend(int fd, const char *fmt, va_list ap) -{ - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); -} - void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, va_list ap) { @@ -XXX,XX +XXX,XX @@ void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap) qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap); } -QDict *qmp_fdv(int fd, const char *fmt, va_list ap) -{ - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); - - return qmp_fd_receive(fd); -} - QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, va_list ap) { @@ -XXX,XX +XXX,XX @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) return qtest_qmp_receive(s); } -QDict *qmp_fd(int fd, const char *fmt, ...) -{ - va_list ap; - QDict *response; - - va_start(ap, fmt); - response = qmp_fdv(fd, fmt, ap); - va_end(ap); - return response; -} - -void qmp_fd_send(int fd, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - qmp_fd_vsend(fd, fmt, ap); - va_end(ap); -} - QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, ...) { @@ -XXX,XX +XXX,XX @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...) va_end(ap); } -void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) -{ - bool log = getenv("QTEST_LOG") != NULL; - char *str = g_strdup_vprintf(fmt, ap); - - if (log) { - fprintf(stderr, "%s", str); - } - socket_send(fd, str, strlen(str)); - g_free(str); -} - -void qmp_fd_send_raw(int fd, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - qmp_fd_vsend_raw(fd, fmt, ap); - va_end(ap); -} - void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) { va_list ap; @@ -XXX,XX +XXX,XX @@ void qtest_qmp_device_del(QTestState *qts, const char *id) qtest_qmp_eventwait(qts, "DEVICE_DELETED"); } -bool qmp_rsp_is_err(QDict *rsp) -{ - QDict *error = qdict_get_qdict(rsp, "error"); - qobject_unref(rsp); - return !!error; -} - -void qmp_expect_error_and_unref(QDict *rsp, const char *class) -{ - QDict *error = qdict_get_qdict(rsp, "error"); - - g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class); - g_assert_nonnull(qdict_get_try_str(error, "desc")); - g_assert(!qdict_haskey(rsp, "return")); - - qobject_unref(rsp); -} - static void qtest_client_set_tx_handler(QTestState *s, QTestSendFn send) { diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqos/meson.build +++ b/tests/qtest/libqos/meson.build @@ -XXX,XX +XXX,XX @@ -libqos_srcs = files('../libqtest.c', +libqos_srcs = files( + '../libqtest.c', + '../libqmp.c', + 'qgraph.c', 'qos_external.c', 'pci.c', diff --git a/tests/unit/meson.build b/tests/unit/meson.build index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -XXX,XX +XXX,XX @@ if have_system endif if have_ga and targetos == 'linux' - tests += {'test-qga': ['../qtest/libqtest.c']} + tests += {'test-qga': ['../qtest/libqmp.c']} test_deps += {'test-qga': qga} endif -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/qtest/libqmp.h | 2 ++ tests/qtest/libqmp.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqmp.h +++ b/tests/qtest/libqmp.h @@ -XXX,XX +XXX,XX @@ #include "qapi/qmp/qdict.h" QDict *qmp_fd_receive(int fd); +#ifndef G_OS_WIN32 void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0); +#endif void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqmp.c +++ b/tests/qtest/libqmp.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" - #include "libqmp.h" +#include <unistd.h> +#include <stdlib.h> +#ifndef G_OS_WIN32 +#include <sys/socket.h> +#endif + +#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/qjson.h" @@ -XXX,XX +XXX,XX @@ QDict *qmp_fd_receive(int fd) return qmp.response; } +#ifndef G_OS_WIN32 /* Sends a message and file descriptors to the socket. * It's needed for qmp-commands like getfd/add-fd */ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, @@ -XXX,XX +XXX,XX @@ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, } while (ret < 0 && errno == EINTR); g_assert_cmpint(ret, >, 0); } +#endif /** * Allow users to send a message without waiting for the reply, * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, - const char *fmt, va_list ap) +static void +_qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) { QObject *qobj; +#ifdef G_OS_WIN32 + assert(fds_num == 0); +#endif + /* Going through qobject ensures we escape strings properly */ qobj = qobject_from_vjsonf_nofail(fmt, ap); @@ -XXX,XX +XXX,XX @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, if (log) { fprintf(stderr, "%s", str->str); } + +#ifndef G_OS_WIN32 /* Send QMP request */ if (fds && fds_num > 0) { socket_send_fds(fd, fds, fds_num, str->str, str->len); - } else { + } else +#endif + { socket_send(fd, str->str, str->len); } @@ -XXX,XX +XXX,XX @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, } } +#ifndef G_OS_WIN32 +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + _qmp_fd_vsend_fds(fd, fds, fds_num, fmt, ap); +} +#endif + void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); } QDict *qmp_fdv(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); return qmp_fd_receive(fd); } -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> API available since glib 2.30. It also preserves errno. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- hw/misc/ivshmem.c | 2 +- util/event_notifier-posix.c | 6 ++---- util/main-loop.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index XXXXXXX..XXXXXXX 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -XXX,XX +XXX,XX @@ static void process_msg_connect(IVShmemState *s, uint16_t posn, int fd, IVSHMEM_DPRINTF("eventfds[%d][%d] = %d\n", posn, vector, fd); event_notifier_init_fd(&peer->eventfds[vector], fd); - fcntl_setfl(fd, O_NONBLOCK); /* msix/irqfd poll non block */ + g_unix_set_fd_nonblocking(fd, true, NULL); /* msix/irqfd poll non block */ if (posn == s->vm_id) { setup_interrupt(s, vector, errp); diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -XXX,XX +XXX,XX @@ int event_notifier_init(EventNotifier *e, int active) if (qemu_pipe(fds) < 0) { return -errno; } - ret = fcntl_setfl(fds[0], O_NONBLOCK); - if (ret < 0) { + if (!g_unix_set_fd_nonblocking(fds[0], true, NULL)) { ret = -errno; goto fail; } - ret = fcntl_setfl(fds[1], O_NONBLOCK); - if (ret < 0) { + if (!g_unix_set_fd_nonblocking(fds[1], true, NULL)) { ret = -errno; goto fail; } diff --git a/util/main-loop.c b/util/main-loop.c index XXXXXXX..XXXXXXX 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -XXX,XX +XXX,XX @@ static int qemu_signal_init(Error **errp) return -errno; } - fcntl_setfl(sigfd, O_NONBLOCK); + g_unix_set_fd_nonblocking(sigfd, true, NULL); qemu_set_fd_handler(sigfd, sigfd_handler, NULL, (void *)(intptr_t)sigfd); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> It is only used by block/file-posix.c, move it there. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/sysemu/os-posix.h | 2 -- block/file-posix.c | 15 +++++++++++++++ util/oslib-posix.c | 15 --------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index XXXXXXX..XXXXXXX 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -XXX,XX +XXX,XX @@ static inline void qemu_funlockfile(FILE *f) funlockfile(f); } -int fcntl_setfl(int fd, int flag); - #ifdef __cplusplus } #endif diff --git a/block/file-posix.c b/block/file-posix.c index XXXXXXX..XXXXXXX 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -XXX,XX +XXX,XX @@ static int raw_handle_perm_lock(BlockDriverState *bs, return ret; } +/* Sets a specific flag */ +static int fcntl_setfl(int fd, int flag) +{ + int flags; + + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + return -errno; + } + if (fcntl(fd, F_SETFL, flags | flag) == -1) { + return -errno; + } + return 0; +} + static int raw_reconfigure_getfd(BlockDriverState *bs, int flags, int *open_flags, uint64_t perm, bool force_dup, Error **errp) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ size_t qemu_get_host_physmem(void) return 0; } -/* Sets a specific flag */ -int fcntl_setfl(int fd, int flag) -{ - int flags; - - flags = fcntl(fd, F_GETFL); - if (flags == -1) { - return -errno; - } - if (fcntl(fd, F_SETFL, flags | flag) == -1) { - return -errno; - } - return 0; -} - int qemu_msync(void *addr, size_t length, int fd) { size_t align_mask = ~(qemu_real_host_page_size() - 1); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> GLib g_unix_open_pipe() is essentially like qemu_pipe(), available since 2.30. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/qemu/osdep.h | 4 ---- qemu-nbd.c | 5 +++-- util/event_notifier-posix.c | 2 +- util/oslib-posix.c | 22 ---------------------- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -XXX,XX +XXX,XX @@ static inline void qemu_timersub(const struct timeval *val1, ssize_t qemu_write_full(int fd, const void *buf, size_t count) G_GNUC_WARN_UNUSED_RESULT; -#ifndef _WIN32 -int qemu_pipe(int pipefd[2]); -#endif - void qemu_set_cloexec(int fd); void fips_set_state(bool requested); diff --git a/qemu-nbd.c b/qemu-nbd.c index XXXXXXX..XXXXXXX 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) if ((device && !verbose) || fork_process) { #ifndef WIN32 + g_autoptr(GError) err = NULL; int stderr_fd[2]; pid_t pid; int ret; - if (qemu_pipe(stderr_fd) < 0) { + if (!g_unix_open_pipe(stderr_fd, FD_CLOEXEC, &err)) { error_report("Error setting up communication pipe: %s", - strerror(errno)); + err->message); exit(EXIT_FAILURE); } diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/event_notifier-posix.c +++ b/util/event_notifier-posix.c @@ -XXX,XX +XXX,XX @@ int event_notifier_init(EventNotifier *e, int active) if (errno != ENOSYS) { return -errno; } - if (qemu_pipe(fds) < 0) { + if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) { return -errno; } if (!g_unix_set_fd_nonblocking(fds[0], true, NULL)) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ void qemu_set_cloexec(int fd) assert(f != -1); } -/* - * Creates a pipe with FD_CLOEXEC set on both file descriptors - */ -int qemu_pipe(int pipefd[2]) -{ - int ret; - -#ifdef CONFIG_PIPE2 - ret = pipe2(pipefd, O_CLOEXEC); - if (ret != -1 || errno != ENOSYS) { - return ret; - } -#endif - ret = pipe(pipefd); - if (ret == 0) { - qemu_set_cloexec(pipefd[0]); - qemu_set_cloexec(pipefd[1]); - } - - return ret; -} - char * qemu_get_local_state_dir(void) { -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- util/compatfd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/util/compatfd.c b/util/compatfd.c index XXXXXXX..XXXXXXX 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -XXX,XX +XXX,XX @@ static int qemu_signalfd_compat(const sigset_t *mask) info = g_malloc(sizeof(*info)); - if (pipe(fds) == -1) { + if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) { g_free(info); return -1; } - qemu_set_cloexec(fds[0]); - qemu_set_cloexec(fds[1]); - memcpy(&info->mask, mask, sizeof(*mask)); info->fd = fds[1]; -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ void qmp_guest_set_user_password(const char *username, goto out; } - if (pipe(datafd) < 0) { + if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { error_setg(errp, "cannot create pipe FDs"); goto out; } -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/qtest/ivshmem-test.c | 5 +++-- tests/unit/test-io-channel-file.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/ivshmem-test.c +++ b/tests/qtest/ivshmem-test.c @@ -XXX,XX +XXX,XX @@ static void setup_vm_with_server(IVState *s, int nvectors) static void test_ivshmem_server(void) { + g_autoptr(GError) err = NULL; IVState state1, state2, *s1, *s2; ServerThread thread; IvshmemServer server; @@ -XXX,XX +XXX,XX @@ static void test_ivshmem_server(void) g_assert_cmpint(ret, ==, 0); thread.server = &server; - ret = pipe(thread.pipe); - g_assert_cmpint(ret, ==, 0); + g_unix_open_pipe(thread.pipe, FD_CLOEXEC, &err); + g_assert_no_error(err); thread.thread = g_thread_new("ivshmem-server", server_thread, &thread); g_assert(thread.thread != NULL); diff --git a/tests/unit/test-io-channel-file.c b/tests/unit/test-io-channel-file.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-io-channel-file.c +++ b/tests/unit/test-io-channel-file.c @@ -XXX,XX +XXX,XX @@ static void test_io_channel_pipe(bool async) QIOChannelTest *test; int fd[2]; - if (pipe(fd) < 0) { + if (!g_unix_open_pipe(fd, FD_CLOEXEC, NULL)) { perror("pipe"); abort(); } -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- os-posix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/os-posix.c b/os-posix.c index XXXXXXX..XXXXXXX 100644 --- a/os-posix.c +++ b/os-posix.c @@ -XXX,XX +XXX,XX @@ void os_daemonize(void) pid_t pid; int fds[2]; - if (pipe(fds) == -1) { + if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) { exit(1); } @@ -XXX,XX +XXX,XX @@ void os_daemonize(void) close(fds[0]); daemon_pipe = fds[1]; - qemu_set_cloexec(daemon_pipe); setsid(); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tools/virtiofsd/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c index XXXXXXX..XXXXXXX 100644 --- a/tools/virtiofsd/helper.c +++ b/tools/virtiofsd/helper.c @@ -XXX,XX +XXX,XX @@ int fuse_daemonize(int foreground) int waiter[2]; char completed; - if (pipe(waiter)) { + if (!g_unix_open_pipe(waiter, FD_CLOEXEC, NULL)) { fuse_log(FUSE_LOG_ERR, "fuse_daemonize: pipe: %s\n", strerror(errno)); return -1; -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- io/channel-command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/channel-command.c b/io/channel-command.c index XXXXXXX..XXXXXXX 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -XXX,XX +XXX,XX @@ qio_channel_command_new_spawn(const char *const argv[], } } - if ((!stdinnull && pipe(stdinfd) < 0) || - (!stdoutnull && pipe(stdoutfd) < 0)) { + if ((!stdinnull && !g_unix_open_pipe(stdinfd, FD_CLOEXEC, NULL)) || + (!stdoutnull && !g_unix_open_pipe(stdoutfd, FD_CLOEXEC, NULL))) { error_setg_errno(errp, errno, "Unable to open pipe"); goto error; -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- net/tap-bsd.c | 4 ++-- net/tap-linux.c | 2 +- net/tap-solaris.c | 2 +- tests/qtest/fuzz/virtio_net_fuzz.c | 2 +- tests/unit/test-iov.c | 4 ++-- util/oslib-posix.c | 16 ++-------------- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index XXXXXXX..XXXXXXX 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -XXX,XX +XXX,XX @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } } - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } @@ -XXX,XX +XXX,XX @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, goto error; } - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; error: diff --git a/net/tap-linux.c b/net/tap-linux.c index XXXXXXX..XXXXXXX 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -XXX,XX +XXX,XX @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } pstrcpy(ifname, ifname_size, ifr.ifr_name); - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } diff --git a/net/tap-solaris.c b/net/tap-solaris.c index XXXXXXX..XXXXXXX 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -XXX,XX +XXX,XX @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } } - fcntl(fd, F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(fd, true, NULL); return fd; } diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_net_fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/virtio_net_fuzz.c +++ b/tests/qtest/fuzz/virtio_net_fuzz.c @@ -XXX,XX +XXX,XX @@ static void *virtio_net_test_setup_socket(GString *cmd_line, void *arg) { int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds); g_assert_cmpint(ret, !=, -1); - fcntl(sockfds[0], F_SETFL, O_NONBLOCK); + g_unix_set_fd_nonblocking(sockfds[0], true, NULL); sockfds_initialized = true; g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ", sockfds[1]); diff --git a/tests/unit/test-iov.c b/tests/unit/test-iov.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-iov.c +++ b/tests/unit/test-iov.c @@ -XXX,XX +XXX,XX @@ static void test_io(void) close(sv[0]); FD_SET(sv[1], &fds); - fcntl(sv[1], F_SETFL, O_RDWR|O_NONBLOCK); + g_unix_set_fd_nonblocking(sv[1], true, NULL); r = g_test_rand_int_range(sz / 2, sz); setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &r, sizeof(r)); @@ -XXX,XX +XXX,XX @@ static void test_io(void) close(sv[1]); FD_SET(sv[0], &fds); - fcntl(sv[0], F_SETFL, O_RDWR|O_NONBLOCK); + g_unix_set_fd_nonblocking(sv[0], true, NULL); r = g_test_rand_int_range(sz / 2, sz); setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &r, sizeof(r)); usleep(500000); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ void qemu_anon_ram_free(void *ptr, size_t size) void qemu_set_block(int fd) { - int f; - f = fcntl(fd, F_GETFL); - assert(f != -1); - f = fcntl(fd, F_SETFL, f & ~O_NONBLOCK); - assert(f != -1); + g_unix_set_fd_nonblocking(fd, false, NULL); } int qemu_try_set_nonblock(int fd) { - int f; - f = fcntl(fd, F_GETFL); - if (f == -1) { - return -errno; - } - if (fcntl(fd, F_SETFL, f | O_NONBLOCK) == -1) { - return -errno; - } - return 0; + return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -1; } void qemu_set_nonblock(int fd) -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The function isn't used outside of qio_channel_command_new_spawn(), which is !win32-specific. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/io/channel-command.h | 25 ------------------------- io/channel-command.c | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/include/io/channel-command.h b/include/io/channel-command.h index XXXXXXX..XXXXXXX 100644 --- a/include/io/channel-command.h +++ b/include/io/channel-command.h @@ -XXX,XX +XXX,XX @@ struct QIOChannelCommand { }; -/** - * qio_channel_command_new_pid: - * @writefd: the FD connected to the command's stdin - * @readfd: the FD connected to the command's stdout - * @pid: the PID of the running child command - * @errp: pointer to a NULL-initialized error object - * - * Create a channel for performing I/O with the - * previously spawned command identified by @pid. - * The two file descriptors provide the connection - * to command's stdio streams, either one or which - * may be -1 to indicate that stream is not open. - * - * The channel will take ownership of the process - * @pid and will kill it when closing the channel. - * Similarly it will take responsibility for - * closing the file descriptors @writefd and @readfd. - * - * Returns: the command channel object, or NULL on error - */ -QIOChannelCommand * -qio_channel_command_new_pid(int writefd, - int readfd, - pid_t pid); - /** * qio_channel_command_new_spawn: * @argv: the NULL terminated list of command arguments diff --git a/io/channel-command.c b/io/channel-command.c index XXXXXXX..XXXXXXX 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -XXX,XX +XXX,XX @@ #include "qemu/sockets.h" #include "trace.h" - -QIOChannelCommand * +#ifndef WIN32 +/** + * qio_channel_command_new_pid: + * @writefd: the FD connected to the command's stdin + * @readfd: the FD connected to the command's stdout + * @pid: the PID of the running child command + * @errp: pointer to a NULL-initialized error object + * + * Create a channel for performing I/O with the + * previously spawned command identified by @pid. + * The two file descriptors provide the connection + * to command's stdio streams, either one or which + * may be -1 to indicate that stream is not open. + * + * The channel will take ownership of the process + * @pid and will kill it when closing the channel. + * Similarly it will take responsibility for + * closing the file descriptors @writefd and @readfd. + * + * Returns: the command channel object, or NULL on error + */ +static QIOChannelCommand * qio_channel_command_new_pid(int writefd, int readfd, pid_t pid) @@ -XXX,XX +XXX,XX @@ qio_channel_command_new_pid(int writefd, return ioc; } - -#ifndef WIN32 QIOChannelCommand * qio_channel_command_new_spawn(const char *const argv[], int flags, -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Those calls are either for non-socket fd, or are POSIX-specific. Use the dedicated GLib API. (qemu_set_nonblock() is for socket-like) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- chardev/char-fd.c | 4 ++-- chardev/char-pty.c | 5 ++++- chardev/char-serial.c | 5 ++++- chardev/char-stdio.c | 5 ++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -XXX,XX +XXX,XX @@ void qemu_chr_open_fd(Chardev *chr, FDChardev *s = FD_CHARDEV(chr); g_autofree char *name = NULL; - if (fd_out >= 0) { - qemu_set_nonblock(fd_out); + if (fd_out >= 0 && !g_unix_set_fd_nonblocking(fd_out, true, NULL)) { + assert(!"Failed to set FD nonblocking"); } if (fd_out == fd_in && fd_in >= 0) { diff --git a/chardev/char-pty.c b/chardev/char-pty.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -XXX,XX +XXX,XX @@ static void char_pty_open(Chardev *chr, } close(slave_fd); - qemu_set_nonblock(master_fd); + if (!g_unix_set_fd_nonblocking(master_fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return; + } chr->filename = g_strdup_printf("pty:%s", pty_name); qemu_printf("char device redirected to %s (label %s)\n", diff --git a/chardev/char-serial.c b/chardev/char-serial.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -XXX,XX +XXX,XX @@ static void qmp_chardev_open_serial(Chardev *chr, if (fd < 0) { return; } - qemu_set_nonblock(fd); + if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return; + } tty_serial_init(fd, 115200, 'N', 8, 1); qemu_chr_open_fd(chr, fd, fd); diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -XXX,XX +XXX,XX @@ static void qemu_chr_open_stdio(Chardev *chr, stdio_in_use = true; old_fd0_flags = fcntl(0, F_GETFL); tcgetattr(0, &oldtty); - qemu_set_nonblock(0); + if (!g_unix_set_fd_nonblocking(0, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return; + } atexit(term_exit); memset(&act, 0, sizeof(act)); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Those calls are non-socket fd, or are POSIX-specific. Use the dedicated GLib API. (qemu_set_nonblock() is for socket-like) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- io/channel-command.c | 16 +++++++++------- io/channel-file.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/io/channel-command.c b/io/channel-command.c index XXXXXXX..XXXXXXX 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -XXX,XX +XXX,XX @@ static int qio_channel_command_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) { +#ifdef WIN32 + /* command spawn is not supported on win32 */ + g_assert_not_reached(); +#else QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc); - if (enabled) { - qemu_set_block(cioc->writefd); - qemu_set_block(cioc->readfd); - } else { - qemu_set_nonblock(cioc->writefd); - qemu_set_nonblock(cioc->readfd); + if (!g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL) || + !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; } - +#endif return 0; } diff --git a/io/channel-file.c b/io/channel-file.c index XXXXXXX..XXXXXXX 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -XXX,XX +XXX,XX @@ static int qio_channel_file_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) { +#ifdef WIN32 + /* not implemented */ + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; +#else QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc); - if (enabled) { - qemu_set_block(fioc->fd); - } else { - qemu_set_nonblock(fioc->fd); + if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; } return 0; +#endif } -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The call is POSIX-specific. Use the dedicated GLib API. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/commands-posix.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, /* set fd non-blocking to avoid common use cases (like reading from a * named pipe) from hanging the agent */ - qemu_set_nonblock(fileno(fh)); + if (!g_unix_set_fd_nonblocking(fileno(fh), true, NULL)) { + fclose(fh); + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; + } handle = guest_file_handle_add(fh, errp); if (handle < 0) { -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Those calls are non-socket fd, or are POSIX-specific. Use the dedicated GLib API. (qemu_set_nonblock() is for socket-like) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- hw/input/virtio-input-host.c | 5 ++++- hw/virtio/vhost-vsock.c | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-host.c +++ b/hw/input/virtio-input-host.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp) error_setg_file_open(errp, errno, vih->evdev); return; } - qemu_set_nonblock(vih->fd); + if (!g_unix_set_fd_nonblocking(vih->fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + goto err_close; + } rc = ioctl(vih->fd, EVIOCGVERSION, &ver); if (rc < 0) { diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c index XXXXXXX..XXXXXXX 100644 --- a/hw/virtio/vhost-vsock.c +++ b/hw/virtio/vhost-vsock.c @@ -XXX,XX +XXX,XX @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) return; } - ret = qemu_try_set_nonblock(vhostfd); - if (ret < 0) { - error_setg_errno(errp, -ret, + if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { + error_setg_errno(errp, errno, "vhost-vsock: unable to set non-blocking mode"); return; } @@ -XXX,XX +XXX,XX @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp) return; } - qemu_set_nonblock(vhostfd); + if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { + error_setg_errno(errp, errno, + "Failed to set FD nonblocking"); + return; + } } vhost_vsock_common_realize(vdev, "vhost-vsock"); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The call is POSIX-specific. Use the dedicated GLib API. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- ui/input-linux.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -XXX,XX +XXX,XX @@ static void input_linux_complete(UserCreatable *uc, Error **errp) error_setg_file_open(errp, errno, il->evdev); return; } - qemu_set_nonblock(il->fd); + if (!g_unix_set_fd_nonblocking(il->fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return; + } rc = ioctl(il->fd, EVIOCGVERSION, &ver); if (rc < 0) { -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Those calls are POSIX-specific. Use the dedicated GLib API. (qemu_set_nonblock() is for socket-like) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- net/tap.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index XXXXXXX..XXXXXXX 100644 --- a/net/tap.c +++ b/net/tap.c @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, return -1; } - qemu_set_nonblock(fd); + if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; + } vnet_hdr = tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { close(fd); @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } if (vhostfdname) { - int ret; - vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, &err); if (vhostfd == -1) { if (tap->has_vhostforce && tap->vhostforce) { @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } return; } - ret = qemu_try_set_nonblock(vhostfd); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", + if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { + error_setg_errno(errp, errno, "%s: Can't use file descriptor %d", name, fd); return; } @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, } return; } - qemu_set_nonblock(vhostfd); + if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return; + } } options.opaque = (void *)(uintptr_t)vhostfd; options.nvqs = 2; @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } - ret = qemu_try_set_nonblock(fd); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", + if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + error_setg_errno(errp, errno, "%s: Can't use file descriptor %d", name, fd); close(fd); return -1; @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, goto free_fail; } - ret = qemu_try_set_nonblock(fd); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", + ret = g_unix_set_fd_nonblocking(fd, true, NULL); + if (!ret) { + error_setg_errno(errp, errno, "%s: Can't use file descriptor %d", name, fd); goto free_fail; } @@ -XXX,XX +XXX,XX @@ free_fail: return -1; } - qemu_set_nonblock(fd); + if (!g_unix_set_fd_nonblocking(fd, true, NULL)) { + error_setg_errno(errp, errno, "Failed to set FD nonblocking"); + return -1; + } vnet_hdr = tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { close(fd); -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The call is POSIX-specific. Use the dedicated GLib API. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/qtest/vhost-user-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -XXX,XX +XXX,XX @@ static int chr_can_read(void *opaque) static void chr_read(void *opaque, const uint8_t *buf, int size) { + g_autoptr(GError) err = NULL; TestServer *s = opaque; CharBackend *chr = &s->chr; VhostUserMsg msg; @@ -XXX,XX +XXX,XX @@ static void chr_read(void *opaque, const uint8_t *buf, int size) * The receive function forces it to be blocking, * so revert it back to non-blocking. */ - qemu_set_nonblock(fd); + g_unix_set_fd_nonblocking(fd, true, &err); + g_assert_no_error(err); break; case VHOST_USER_SET_LOG_BASE: -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The qemu_*block() functions are meant to be be used with sockets (the win32 implementation expects SOCKET) Over time, those functions where used with Win32 SOCKET or file-descriptors interchangeably. But for portability, they must only be used with socket-like file-descriptors. FDs can use g_unix_set_fd_nonblocking() instead. Rename the functions with "socket" in the name to prevent bad usages. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/qemu/sockets.h | 6 +++--- chardev/char-socket.c | 2 +- contrib/ivshmem-server/ivshmem-server.c | 2 +- hw/hyperv/syndbg.c | 2 +- hw/virtio/vhost-user.c | 2 +- io/channel-socket.c | 6 +++--- net/l2tpv3.c | 2 +- net/socket.c | 10 +++++----- qga/channel-posix.c | 2 +- tests/unit/socket-helpers.c | 2 +- tests/unit/test-crypto-tlssession.c | 8 ++++---- util/oslib-posix.c | 8 ++++---- util/oslib-win32.c | 8 ++++---- util/vhost-user-server.c | 4 ++-- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -XXX,XX +XXX,XX @@ int qemu_socket(int domain, int type, int protocol); int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); -void qemu_set_block(int fd); -int qemu_try_set_nonblock(int fd); -void qemu_set_nonblock(int fd); +void qemu_socket_set_block(int fd); +int qemu_socket_try_set_nonblock(int fd); +void qemu_socket_set_nonblock(int fd); int socket_set_fast_reuse(int fd); #ifdef WIN32 diff --git a/chardev/char-socket.c b/chardev/char-socket.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -XXX,XX +XXX,XX @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len) } /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_set_block(fd); + qemu_socket_set_block(fd); #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c index XXXXXXX..XXXXXXX 100644 --- a/contrib/ivshmem-server/ivshmem-server.c +++ b/contrib/ivshmem-server/ivshmem-server.c @@ -XXX,XX +XXX,XX @@ ivshmem_server_handle_new_conn(IvshmemServer *server) return -1; } - qemu_set_nonblock(newfd); + qemu_socket_set_nonblock(newfd); IVSHMEM_SERVER_DEBUG(server, "accept()=%d\n", newfd); /* allocate new structure for this peer */ diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c index XXXXXXX..XXXXXXX 100644 --- a/hw/hyperv/syndbg.c +++ b/hw/hyperv/syndbg.c @@ -XXX,XX +XXX,XX @@ static void hv_syndbg_realize(DeviceState *dev, Error **errp) return; } - qemu_set_nonblock(syndbg->socket); + qemu_socket_set_nonblock(syndbg->socket); syndbg->servaddr.sin_port = htons(syndbg->host_port); syndbg->servaddr.sin_family = AF_INET; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index XXXXXXX..XXXXXXX 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -XXX,XX +XXX,XX @@ static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp) error_setg(errp, "%s: Failed to get ufd", __func__); return -EIO; } - qemu_set_nonblock(ufd); + qemu_socket_set_nonblock(ufd); /* register ufd with userfault thread */ u->postcopy_fd.fd = ufd; diff --git a/io/channel-socket.c b/io/channel-socket.c index XXXXXXX..XXXXXXX 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -XXX,XX +XXX,XX @@ static void qio_channel_socket_copy_fds(struct msghdr *msg, } /* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */ - qemu_set_block(fd); + qemu_socket_set_block(fd); #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(fd); @@ -XXX,XX +XXX,XX @@ qio_channel_socket_set_blocking(QIOChannel *ioc, QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); if (enabled) { - qemu_set_block(sioc->fd); + qemu_socket_set_block(sioc->fd); } else { - qemu_set_nonblock(sioc->fd); + qemu_socket_set_nonblock(sioc->fd); } return 0; } diff --git a/net/l2tpv3.c b/net/l2tpv3.c index XXXXXXX..XXXXXXX 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT); s->header_buf = g_malloc(s->header_size); - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); s->fd = fd; s->counter = 0; diff --git a/net/socket.c b/net/socket.c index XXXXXXX..XXXXXXX 100644 --- a/net/socket.c +++ b/net/socket.c @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, } } - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); return fd; fail: if (fd >= 0) @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, error_setg_errno(errp, errno, "can't create stream socket"); return -1; } - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); socket_set_fast_reuse(fd); @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, error_setg_errno(errp, errno, "can't create stream socket"); return -1; } - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); connected = 0; for(;;) { @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, closesocket(fd); return -1; } - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp); if (!s) { @@ -XXX,XX +XXX,XX @@ int net_init_socket(const Netdev *netdev, const char *name, if (fd == -1) { return -1; } - ret = qemu_try_set_nonblock(fd); + ret = qemu_socket_try_set_nonblock(fd); if (ret < 0) { error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", name, fd); diff --git a/qga/channel-posix.c b/qga/channel-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_listen_accept(GIOChannel *channel, g_warning("error converting fd to gsocket: %s", strerror(errno)); goto out; } - qemu_set_nonblock(client_fd); + qemu_socket_set_nonblock(client_fd); ret = ga_channel_client_add(c, client_fd); if (ret) { g_warning("error setting up connection"); diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/socket-helpers.c +++ b/tests/unit/socket-helpers.c @@ -XXX,XX +XXX,XX @@ static int socket_can_bind_connect(const char *hostname, int family) goto cleanup; } - qemu_set_nonblock(cfd); + qemu_socket_set_nonblock(cfd); if (connect(cfd, (struct sockaddr *)&ss, sslen) < 0) { if (errno == EINPROGRESS) { check_soerr = true; diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-crypto-tlssession.c +++ b/tests/unit/test-crypto-tlssession.c @@ -XXX,XX +XXX,XX @@ static void test_crypto_tls_session_psk(void) * thread, so we need these non-blocking to avoid deadlock * of ourselves */ - qemu_set_nonblock(channel[0]); - qemu_set_nonblock(channel[1]); + qemu_socket_set_nonblock(channel[0]); + qemu_socket_set_nonblock(channel[1]); clientCreds = test_tls_creds_psk_create( QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT, @@ -XXX,XX +XXX,XX @@ static void test_crypto_tls_session_x509(const void *opaque) * thread, so we need these non-blocking to avoid deadlock * of ourselves */ - qemu_set_nonblock(channel[0]); - qemu_set_nonblock(channel[1]); + qemu_socket_set_nonblock(channel[0]); + qemu_socket_set_nonblock(channel[1]); #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/" #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/" diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ void qemu_anon_ram_free(void *ptr, size_t size) qemu_ram_munmap(-1, ptr, size); } -void qemu_set_block(int fd) +void qemu_socket_set_block(int fd) { g_unix_set_fd_nonblocking(fd, false, NULL); } -int qemu_try_set_nonblock(int fd) +int qemu_socket_try_set_nonblock(int fd) { return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -1; } -void qemu_set_nonblock(int fd) +void qemu_socket_set_nonblock(int fd) { int f; - f = qemu_try_set_nonblock(fd); + f = qemu_socket_try_set_nonblock(fd); assert(f == 0); } diff --git a/util/oslib-win32.c b/util/oslib-win32.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -XXX,XX +XXX,XX @@ static int socket_error(void) } } -void qemu_set_block(int fd) +void qemu_socket_set_block(int fd) { unsigned long opt = 0; WSAEventSelect(fd, NULL, 0); ioctlsocket(fd, FIONBIO, &opt); } -int qemu_try_set_nonblock(int fd) +int qemu_socket_try_set_nonblock(int fd) { unsigned long opt = 1; if (ioctlsocket(fd, FIONBIO, &opt) != NO_ERROR) { @@ -XXX,XX +XXX,XX @@ int qemu_try_set_nonblock(int fd) return 0; } -void qemu_set_nonblock(int fd) +void qemu_socket_set_nonblock(int fd) { - (void)qemu_try_set_nonblock(fd); + (void)qemu_socket_try_set_nonblock(fd); } int socket_set_fast_reuse(int fd) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index XXXXXXX..XXXXXXX 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -XXX,XX +XXX,XX @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) { int i; for (i = 0; i < vmsg->fd_num; i++) { - qemu_set_nonblock(vmsg->fds[i]); + qemu_socket_set_nonblock(vmsg->fds[i]); } } @@ -XXX,XX +XXX,XX @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->fd = fd; vu_fd_watch->cb = cb; - qemu_set_nonblock(fd); + qemu_socket_set_nonblock(fd); aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev = vu_dev; -- 2.36.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Hi, v3: - changed error_report_err() back to g_critical() - added "qga: make build_fs_mount_list() return a bool" - replaced g_clear_pointer() usage by open-coded version - dropped needless g_autoptr(GError) in tests - rebased, (dropped "include: adjust header guards after renaming") - some commit message rewording - added r-b tags v2: - drop "compiler.h: add QEMU_{BEGIN,END}_IGNORE_INITIALIZER_OVERRIDES", "qobject/json-lexer: disable -Winitializer-overrides warnings" & "qapi/error: add g_autoptr(Error) support" and adjust related code. - add "test/qga: use g_auto wherever sensible" - add r-b tags Marc-André Lureau (15): include: move qemu_*_exec_dir() to cutils util/win32: simplify qemu_get_local_state_dir() tests: make libqmp buildable for win32 qga: flatten safe_open_or_create() osdep: export qemu_open_cloexec() qga: use qemu_open_cloexec() for safe_open_or_create() qga: throw an Error in ga_channel_open() qga: replace qemu_open_old() with qemu_open_cloexec() qga: make build_fs_mount_list() return a bool test/qga: use G_TEST_DIR to locate os-release test file qga/wixl: prefer variables over environment qga/wixl: require Mingw_bin qga/wixl: simplify some pre-processing qga/wixl: replace QEMU_GA_MSI_MINGW_BIN_PATH with glib bindir test/qga: use g_auto wherever sensible configure | 9 +- include/qemu/cutils.h | 7 ++ include/qemu/osdep.h | 9 +- meson.build | 5 +- qemu-io.c | 1 + qga/channel-posix.c | 55 +++++---- qga/commands-posix.c | 164 +++++++++++++-------------- qga/installer/qemu-ga.wxs | 83 +++++--------- qga/meson.build | 11 +- storage-daemon/qemu-storage-daemon.c | 1 + tests/qtest/fuzz/fuzz.c | 1 + tests/qtest/libqmp.c | 34 +++++- tests/qtest/libqmp.h | 2 + tests/unit/test-qga.c | 130 ++++++++------------- util/cutils.c | 108 ++++++++++++++++++ util/osdep.c | 10 +- util/oslib-posix.c | 81 ------------- util/oslib-win32.c | 53 +-------- 18 files changed, 358 insertions(+), 406 deletions(-) -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> The function is required by get_relocated_path() (already in cutils), and used by qemu-ga and may be generally useful. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/qemu/cutils.h | 7 ++ include/qemu/osdep.h | 8 -- qemu-io.c | 1 + storage-daemon/qemu-storage-daemon.c | 1 + tests/qtest/fuzz/fuzz.c | 1 + util/cutils.c | 108 +++++++++++++++++++++++++++ util/oslib-posix.c | 81 -------------------- util/oslib-win32.c | 36 --------- 8 files changed, 118 insertions(+), 125 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -XXX,XX +XXX,XX @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n); */ int qemu_pstrcmp0(const char **str1, const char **str2); +/* Find program directory, and save it for later usage with + * qemu_get_exec_dir(). + * Try OS specific API first, if not working, parse from argv0. */ +void qemu_init_exec_dir(const char *argv0); + +/* Get the saved exec dir. */ +const char *qemu_get_exec_dir(void); /** * get_relocated_path: diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -XXX,XX +XXX,XX @@ void qemu_set_cloexec(int fd); */ char *qemu_get_local_state_dir(void); -/* Find program directory, and save it for later usage with - * qemu_get_exec_dir(). - * Try OS specific API first, if not working, parse from argv0. */ -void qemu_init_exec_dir(const char *argv0); - -/* Get the saved exec dir. */ -const char *qemu_get_exec_dir(void); - /** * qemu_getauxval: * @type: the auxiliary vector key to lookup diff --git a/qemu-io.c b/qemu-io.c index XXXXXXX..XXXXXXX 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -XXX,XX +XXX,XX @@ #endif #include "qemu/help-texts.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qemu-io.h" #include "qemu/error-report.h" diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index XXXXXXX..XXXXXXX 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -XXX,XX +XXX,XX @@ #include "qemu/help-texts.h" #include "qemu-version.h" +#include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/help_option.h" diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -XXX,XX +XXX,XX @@ #include <wordexp.h> +#include "qemu/cutils.h" #include "qemu/datadir.h" #include "sysemu/sysemu.h" #include "sysemu/qtest.h" diff --git a/util/cutils.c b/util/cutils.c index XXXXXXX..XXXXXXX 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -XXX,XX +XXX,XX @@ static inline const char *next_component(const char *dir, int *p_len) return dir; } +static const char *exec_dir; + +void qemu_init_exec_dir(const char *argv0) +{ +#ifdef G_OS_WIN32 + char *p; + char buf[MAX_PATH]; + DWORD len; + + if (exec_dir) { + return; + } + + len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); + if (len == 0) { + return; + } + + buf[len] = 0; + p = buf + len - 1; + while (p != buf && *p != '\\') { + p--; + } + *p = 0; + if (access(buf, R_OK) == 0) { + exec_dir = g_strdup(buf); + } else { + exec_dir = CONFIG_BINDIR; + } +#else + char *p = NULL; + char buf[PATH_MAX]; + + if (exec_dir) { + return; + } + +#if defined(__linux__) + { + int len; + len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); + if (len > 0) { + buf[len] = 0; + p = buf; + } + } +#elif defined(__FreeBSD__) \ + || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) + { +#if defined(__FreeBSD__) + static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; +#else + static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; +#endif + size_t len = sizeof(buf) - 1; + + *buf = '\0'; + if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && + *buf) { + buf[sizeof(buf) - 1] = '\0'; + p = buf; + } + } +#elif defined(__APPLE__) + { + char fpath[PATH_MAX]; + uint32_t len = sizeof(fpath); + if (_NSGetExecutablePath(fpath, &len) == 0) { + p = realpath(fpath, buf); + if (!p) { + return; + } + } + } +#elif defined(__HAIKU__) + { + image_info ii; + int32_t c = 0; + + *buf = '\0'; + while (get_next_image_info(0, &c, &ii) == B_OK) { + if (ii.type == B_APP_IMAGE) { + strncpy(buf, ii.name, sizeof(buf)); + buf[sizeof(buf) - 1] = 0; + p = buf; + break; + } + } + } +#endif + /* If we don't have any way of figuring out the actual executable + location then try argv[0]. */ + if (!p && argv0) { + p = realpath(argv0, buf); + } + if (p) { + exec_dir = g_path_get_dirname(p); + } else { + exec_dir = CONFIG_BINDIR; + } +#endif +} + +const char *qemu_get_exec_dir(void) +{ + return exec_dir; +} + char *get_relocated_path(const char *dir) { size_t prefix_len = strlen(CONFIG_PREFIX); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -XXX,XX +XXX,XX @@ void qemu_set_tty_echo(int fd, bool echo) tcsetattr(fd, TCSANOW, &tty); } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - char *p = NULL; - char buf[PATH_MAX]; - - if (exec_dir) { - return; - } - -#if defined(__linux__) - { - int len; - len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); - if (len > 0) { - buf[len] = 0; - p = buf; - } - } -#elif defined(__FreeBSD__) \ - || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) - { -#if defined(__FreeBSD__) - static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; -#else - static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; -#endif - size_t len = sizeof(buf) - 1; - - *buf = '\0'; - if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && - *buf) { - buf[sizeof(buf) - 1] = '\0'; - p = buf; - } - } -#elif defined(__APPLE__) - { - char fpath[PATH_MAX]; - uint32_t len = sizeof(fpath); - if (_NSGetExecutablePath(fpath, &len) == 0) { - p = realpath(fpath, buf); - if (!p) { - return; - } - } - } -#elif defined(__HAIKU__) - { - image_info ii; - int32_t c = 0; - - *buf = '\0'; - while (get_next_image_info(0, &c, &ii) == B_OK) { - if (ii.type == B_APP_IMAGE) { - strncpy(buf, ii.name, sizeof(buf)); - buf[sizeof(buf) - 1] = 0; - p = buf; - break; - } - } - } -#endif - /* If we don't have any way of figuring out the actual executable - location then try argv[0]. */ - if (!p && argv0) { - p = realpath(argv0, buf); - } - if (p) { - exec_dir = g_path_get_dirname(p); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - #ifdef CONFIG_LINUX static void sigbus_handler(int signal, siginfo_t *siginfo, void *ctx) #else /* CONFIG_LINUX */ diff --git a/util/oslib-win32.c b/util/oslib-win32.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -XXX,XX +XXX,XX @@ void qemu_set_tty_echo(int fd, bool echo) } } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - - char *p; - char buf[MAX_PATH]; - DWORD len; - - if (exec_dir) { - return; - } - - len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); - if (len == 0) { - return; - } - - buf[len] = 0; - p = buf + len - 1; - while (p != buf && *p != '\\') { - p--; - } - *p = 0; - if (access(buf, R_OK) == 0) { - exec_dir = g_strdup(buf); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - int getpagesize(void) { SYSTEM_INFO system_info; -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> SHGetFolderPath() is a deprecated API: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha It is a wrapper for SHGetKnownFolderPath() and CSIDL_COMMON_PATH is mapped to FOLDERID_ProgramData: https://docs.microsoft.com/en-us/windows/win32/shell/csidl g_get_system_data_dirs() is a suitable replacement, as it will have FOLDERID_ProgramData in the returned list. However, it follows the XDG Base Directory Specification, if `XDG_DATA_DIRS` is defined, it will be returned instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> --- util/oslib-win32.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index XXXXXXX..XXXXXXX 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -XXX,XX +XXX,XX @@ #include "qemu/error-report.h" #include <malloc.h> -/* this must come after including "trace.h" */ -#include <shlobj.h> - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; @@ -XXX,XX +XXX,XX @@ int qemu_get_thread_id(void) char * qemu_get_local_state_dir(void) { - HRESULT result; - char base_path[MAX_PATH+1] = ""; + const char * const *data_dirs = g_get_system_data_dirs(); - result = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, - /* SHGFP_TYPE_CURRENT */ 0, base_path); - if (result != S_OK) { - /* misconfigured environment */ - g_critical("CSIDL_COMMON_APPDATA unavailable: %ld", (long)result); - abort(); - } - return g_strdup(base_path); + g_assert(data_dirs && data_dirs[0]); + + return g_strdup(data_dirs[0]); } void qemu_set_tty_echo(int fd, bool echo) -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> --- tests/qtest/libqmp.c | 34 +++++++++++++++++++++++++++++----- tests/qtest/libqmp.h | 2 ++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqmp.c +++ b/tests/qtest/libqmp.c @@ -XXX,XX +XXX,XX @@ #include "libqmp.h" +#ifndef G_OS_WIN32 +#include <sys/socket.h> +#endif + +#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/qjson.h" @@ -XXX,XX +XXX,XX @@ QDict *qmp_fd_receive(int fd) return qmp.response; } +#ifndef G_OS_WIN32 /* Sends a message and file descriptors to the socket. * It's needed for qmp-commands like getfd/add-fd */ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, @@ -XXX,XX +XXX,XX @@ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, } while (ret < 0 && errno == EINTR); g_assert_cmpint(ret, >, 0); } +#endif /** * Allow users to send a message without waiting for the reply, * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, - const char *fmt, va_list ap) +static void +_qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) { QObject *qobj; +#ifdef G_OS_WIN32 + assert(fds_num == 0); +#endif + /* Going through qobject ensures we escape strings properly */ qobj = qobject_from_vjsonf_nofail(fmt, ap); @@ -XXX,XX +XXX,XX @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, if (log) { fprintf(stderr, "%s", str->str); } + +#ifndef G_OS_WIN32 /* Send QMP request */ if (fds && fds_num > 0) { socket_send_fds(fd, fds, fds_num, str->str, str->len); - } else { + } else +#endif + { socket_send(fd, str->str, str->len); } @@ -XXX,XX +XXX,XX @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, } } +#ifndef G_OS_WIN32 +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + _qmp_fd_vsend_fds(fd, fds, fds_num, fmt, ap); +} +#endif + void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); } QDict *qmp_fdv(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); return qmp_fd_receive(fd); } diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h index XXXXXXX..XXXXXXX 100644 --- a/tests/qtest/libqmp.h +++ b/tests/qtest/libqmp.h @@ -XXX,XX +XXX,XX @@ #include "qapi/qmp/qdict.h" QDict *qmp_fd_receive(int fd); +#ifndef G_OS_WIN32 void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0); +#endif void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> There is a bit too much nesting in the function, this can be simplified a bit to improve readability. This also helps with the following error handling changes. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/commands-posix.c | 122 ++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ find_open_flag(const char *mode_str, Error **errp) static FILE * safe_open_or_create(const char *path, const char *mode, Error **errp) { - Error *local_err = NULL; int oflag; + int fd = -1; + FILE *f = NULL; + + oflag = find_open_flag(mode, errp); + if (oflag < 0) { + goto end; + } + + /* If the caller wants / allows creation of a new file, we implement it + * with a two step process: open() + (open() / fchmod()). + * + * First we insist on creating the file exclusively as a new file. If + * that succeeds, we're free to set any file-mode bits on it. (The + * motivation is that we want to set those file-mode bits independently + * of the current umask.) + * + * If the exclusive creation fails because the file already exists + * (EEXIST is not possible for any other reason), we just attempt to + * open the file, but in this case we won't be allowed to change the + * file-mode bits on the preexistent file. + * + * The pathname should never disappear between the two open()s in + * practice. If it happens, then someone very likely tried to race us. + * In this case just go ahead and report the ENOENT from the second + * open() to the caller. + * + * If the caller wants to open a preexistent file, then the first + * open() is decisive and its third argument is ignored, and the second + * open() and the fchmod() are never called. + */ + fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); + if (fd == -1 && errno == EEXIST) { + oflag &= ~(unsigned)O_CREAT; + fd = open(path, oflag); + } + if (fd == -1) { + error_setg_errno(errp, errno, + "failed to open file '%s' " + "(mode: '%s')", + path, mode); + goto end; + } - oflag = find_open_flag(mode, &local_err); - if (local_err == NULL) { - int fd; - - /* If the caller wants / allows creation of a new file, we implement it - * with a two step process: open() + (open() / fchmod()). - * - * First we insist on creating the file exclusively as a new file. If - * that succeeds, we're free to set any file-mode bits on it. (The - * motivation is that we want to set those file-mode bits independently - * of the current umask.) - * - * If the exclusive creation fails because the file already exists - * (EEXIST is not possible for any other reason), we just attempt to - * open the file, but in this case we won't be allowed to change the - * file-mode bits on the preexistent file. - * - * The pathname should never disappear between the two open()s in - * practice. If it happens, then someone very likely tried to race us. - * In this case just go ahead and report the ENOENT from the second - * open() to the caller. - * - * If the caller wants to open a preexistent file, then the first - * open() is decisive and its third argument is ignored, and the second - * open() and the fchmod() are never called. - */ - fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); - if (fd == -1 && errno == EEXIST) { - oflag &= ~(unsigned)O_CREAT; - fd = open(path, oflag); - } + qemu_set_cloexec(fd); - if (fd == -1) { - error_setg_errno(&local_err, errno, "failed to open file '%s' " - "(mode: '%s')", path, mode); - } else { - qemu_set_cloexec(fd); + if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { + error_setg_errno(errp, errno, + "failed to set permission 0%03o on new file '%s' (mode: '%s')", + (unsigned)DEFAULT_NEW_FILE_MODE, path, mode); + goto end; + } - if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { - error_setg_errno(&local_err, errno, "failed to set permission " - "0%03o on new file '%s' (mode: '%s')", - (unsigned)DEFAULT_NEW_FILE_MODE, path, mode); - } else { - FILE *f; - - f = fdopen(fd, mode); - if (f == NULL) { - error_setg_errno(&local_err, errno, "failed to associate " - "stdio stream with file descriptor %d, " - "file '%s' (mode: '%s')", fd, path, mode); - } else { - return f; - } - } + f = fdopen(fd, mode); + if (f == NULL) { + error_setg_errno(errp, errno, + "failed to associate stdio stream with file descriptor %d, " + "file '%s' (mode: '%s')", + fd, path, mode); + } - close(fd); - if (oflag & O_CREAT) { - unlink(path); - } +end: + if (f == NULL && fd != -1) { + close(fd); + if (oflag & O_CREAT) { + unlink(path); } } - - error_propagate(errp, local_err); - return NULL; + return f; } int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Used in the next patch, to simplify qga code. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- include/qemu/osdep.h | 1 + util/osdep.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -XXX,XX +XXX,XX @@ void sigaction_invoke(struct sigaction *action, */ int qemu_open_old(const char *name, int flags, ...); int qemu_open(const char *name, int flags, Error **errp); +int qemu_open_cloexec(const char *name, int flags, mode_t mode, Error **errp); int qemu_create(const char *name, int flags, mode_t mode, Error **errp); int qemu_close(int fd); int qemu_unlink(const char *name); diff --git a/util/osdep.c b/util/osdep.c index XXXXXXX..XXXXXXX 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -XXX,XX +XXX,XX @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive) } #endif -static int qemu_open_cloexec(const char *name, int flags, mode_t mode) +int qemu_open_cloexec(const char *name, int flags, mode_t mode, Error **errp) { + ERRP_GUARD(); int ret; + #ifdef O_CLOEXEC ret = open(name, flags | O_CLOEXEC, mode); #else @@ -XXX,XX +XXX,XX @@ static int qemu_open_cloexec(const char *name, int flags, mode_t mode) qemu_set_cloexec(ret); } #endif + if (ret == -1) { + error_setg_errno(errp, errno, "Failed to open file '%s'", name); + } + return ret; } @@ -XXX,XX +XXX,XX @@ qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp) } #endif - ret = qemu_open_cloexec(name, flags, mode); + ret = qemu_open_cloexec(name, flags, mode, NULL); if (ret == -1) { const char *action = flags & O_CREAT ? "create" : "open"; -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> The function takes care of setting CLOEXEC, and reporting error. The reported error message will differ, from: "failed to open file 'foo' (mode: 'r')" to: "Failed to open file 'foo'" Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/commands-posix.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ find_open_flag(const char *mode_str, Error **errp) static FILE * safe_open_or_create(const char *path, const char *mode, Error **errp) { + ERRP_GUARD(); int oflag; int fd = -1; FILE *f = NULL; @@ -XXX,XX +XXX,XX @@ safe_open_or_create(const char *path, const char *mode, Error **errp) * open() is decisive and its third argument is ignored, and the second * open() and the fchmod() are never called. */ - fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); + fd = qemu_open_cloexec(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0, errp); if (fd == -1 && errno == EEXIST) { + error_free(*errp); + *errp = NULL; oflag &= ~(unsigned)O_CREAT; - fd = open(path, oflag); + fd = qemu_open_cloexec(path, oflag, 0, errp); } if (fd == -1) { - error_setg_errno(errp, errno, - "failed to open file '%s' " - "(mode: '%s')", - path, mode); goto end; } - qemu_set_cloexec(fd); - if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { error_setg_errno(errp, errno, "failed to set permission 0%03o on new file '%s' (mode: '%s')", -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Allow for a single point of error reporting, and further refactoring. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/channel-posix.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -XXX,XX +XXX,XX @@ static int ga_channel_client_add(GAChannel *c, int fd) } static gboolean ga_channel_open(GAChannel *c, const gchar *path, - GAChannelMethod method, int fd) + GAChannelMethod method, int fd, Error **errp) { + ERRP_GUARD(); int ret; c->method = method; @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, #endif ); if (fd == -1) { - g_critical("error opening channel: %s", strerror(errno)); + error_setg_errno(errp, errno, "error opening channel"); return false; } #ifdef CONFIG_SOLARIS ret = ioctl(fd, I_SETSIG, S_OUTPUT | S_INPUT | S_HIPRI); if (ret == -1) { - g_critical("error setting event mask for channel: %s", - strerror(errno)); + error_setg_errno(errp, errno, "error setting event mask for channel"); close(fd); return false; } #endif ret = ga_channel_client_add(c, fd); if (ret) { - g_critical("error adding channel to main loop"); + error_setg(errp, "error adding channel to main loop"); close(fd); return false; } @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, assert(fd < 0); fd = qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd == -1) { - g_critical("error opening channel: %s", strerror(errno)); + error_setg_errno(errp, errno, "error opening channel"); return false; } tcgetattr(fd, &tio); @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, tcsetattr(fd, TCSANOW, &tio); ret = ga_channel_client_add(c, fd); if (ret) { - g_critical("error adding channel to main loop"); + error_setg(errp, "error adding channel to main loop"); close(fd); return false; } @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } case GA_CHANNEL_UNIX_LISTEN: { if (fd < 0) { - Error *local_err = NULL; - - fd = unix_listen(path, &local_err); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + fd = unix_listen(path, errp); + if (fd < 0) { return false; } } @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } case GA_CHANNEL_VSOCK_LISTEN: { if (fd < 0) { - Error *local_err = NULL; SocketAddress *addr; char *addr_str; addr_str = g_strdup_printf("vsock:%s", path); - addr = socket_parse(addr_str, &local_err); + addr = socket_parse(addr_str, errp); g_free(addr_str); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + if (!addr) { return false; } - fd = socket_listen(addr, 1, &local_err); + fd = socket_listen(addr, 1, errp); qapi_free_SocketAddress(addr); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + if (fd < 0) { return false; } } @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, break; } default: - g_critical("error binding/listening to specified socket"); + error_setg(errp, "error binding/listening to specified socket"); return false; } @@ -XXX,XX +XXX,XX @@ GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *count) GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, int listen_fd, GAChannelCallback cb, gpointer opaque) { + Error *err = NULL; GAChannel *c = g_new0(GAChannel, 1); c->event_cb = cb; c->user_data = opaque; - if (!ga_channel_open(c, path, method, listen_fd)) { - g_critical("error opening channel"); + if (!ga_channel_open(c, path, method, listen_fd, &err)) { + g_critical("%s", error_get_pretty(err)); + error_free(err); ga_channel_free(c); return NULL; } -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> qemu_open_old() uses qemu_open_internal() which handles special "/dev/fdset/" path for monitor fd sets, set CLOEXEC, and uses Error reporting (and some O_DIRECT special error casing). The monitor fdset handling is unnecessary for qga, use qemu_open_cloexec() instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- qga/channel-posix.c | 14 +++++++++----- qga/commands-posix.c | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -XXX,XX +XXX,XX @@ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include <termios.h> #include "qapi/error.h" #include "qemu/sockets.h" @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, switch (c->method) { case GA_CHANNEL_VIRTIO_SERIAL: { assert(fd < 0); - fd = qemu_open_old(path, O_RDWR | O_NONBLOCK + fd = qemu_open_cloexec( + path, #ifndef CONFIG_SOLARIS - | O_ASYNC + O_ASYNC | #endif - ); + O_RDWR | O_NONBLOCK, + 0, + errp + ); if (fd == -1) { error_setg_errno(errp, errno, "error opening channel"); return false; @@ -XXX,XX +XXX,XX @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, struct termios tio; assert(fd < 0); - fd = qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); + fd = qemu_open_cloexec(path, O_RDWR | O_NOCTTY | O_NONBLOCK, 0, errp); if (fd == -1) { - error_setg_errno(errp, errno, "error opening channel"); return false; } tcgetattr(fd, &tio); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ static GuestDiskInfoList *get_disk_partitions( static void get_nvme_smart(GuestDiskInfo *disk) { + Error *err = NULL; int fd; GuestNVMeSmart *smart; NvmeSmartLog log = {0}; @@ -XXX,XX +XXX,XX @@ static void get_nvme_smart(GuestDiskInfo *disk) | (((sizeof(log) >> 2) - 1) << 16) }; - fd = qemu_open_old(disk->name, O_RDONLY); + fd = qemu_open_cloexec(disk->name, O_RDONLY, 0, &err); if (fd == -1) { - g_debug("Failed to open device: %s: %s", disk->name, g_strerror(errno)); + g_debug("Failed to open device: %s: %s", disk->name, error_get_pretty(err)); + error_free(err); return; } @@ -XXX,XX +XXX,XX @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, } } - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qemu_open_cloexec(mount->dirname, O_RDONLY, 0, errp); if (fd == -1) { - error_setg_errno(errp, errno, "failed to open %s", mount->dirname); goto error; } @@ -XXX,XX +XXX,XX @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) QTAILQ_FOREACH(mount, &mounts, next) { logged = false; - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qemu_open_cloexec(mount->dirname, O_RDONLY, 0, NULL); if (fd == -1) { continue; } @@ -XXX,XX +XXX,XX @@ static void guest_fsfreeze_cleanup(void) GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { + ERRP_GUARD(); GuestFilesystemTrimResponse *response; GuestFilesystemTrimResult *result; int ret = 0; FsMountList mounts; struct FsMount *mount; int fd; - Error *local_err = NULL; struct fstrim_range r; slog("guest-fstrim called"); QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return NULL; } @@ -XXX,XX +XXX,XX @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) QAPI_LIST_PREPEND(response->paths, result); - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qemu_open_cloexec(mount->dirname, O_RDONLY, 0, errp); if (fd == -1) { - result->error = g_strdup_printf("failed to open: %s", - strerror(errno)); + result->error = g_strdup(error_get_pretty(*errp)); result->has_error = true; + g_clear_pointer(errp, error_free); continue; } -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Change build_fs_mount_list() to return bool, in accordance with the guidance under = Rules = in include/qapi/error.h Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Suggested-by: Markus Armbruster <armbru@redhat.com> --- qga/commands-posix.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index XXXXXXX..XXXXXXX 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -XXX,XX +XXX,XX @@ static int dev_major_minor(const char *devpath, /* * Walk the mount table and build a list of local file systems */ -static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) +static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) { struct mntent *ment; FsMount *mount; @@ -XXX,XX +XXX,XX @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) fp = setmntent(mtab, "r"); if (!fp) { error_setg(errp, "failed to open mtab file: '%s'", mtab); - return; + return false; } while ((ment = getmntent(fp))) { @@ -XXX,XX +XXX,XX @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) } endmntent(fp); + return true; } static void decode_mntname(char *name, int len) @@ -XXX,XX +XXX,XX @@ static void decode_mntname(char *name, int len) } } -static void build_fs_mount_list(FsMountList *mounts, Error **errp) +static bool build_fs_mount_list(FsMountList *mounts, Error **errp) { FsMount *mount; char const *mountinfo = "/proc/self/mountinfo"; @@ -XXX,XX +XXX,XX @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp) fp = fopen(mountinfo, "r"); if (!fp) { - build_fs_mount_list_from_mtab(mounts, errp); - return; + return build_fs_mount_list_from_mtab(mounts, errp); } while (getline(&line, &n, fp) != -1) { @@ -XXX,XX +XXX,XX @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp) free(line); fclose(fp); + return true; } #endif @@ -XXX,XX +XXX,XX @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) Error *local_err = NULL; QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return NULL; } @@ -XXX,XX +XXX,XX @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, } QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return -1; } @@ -XXX,XX +XXX,XX @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) Error *local_err = NULL; QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return 0; } @@ -XXX,XX +XXX,XX @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) slog("guest-fstrim called"); QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, errp); - if (*errp) { + if (!build_fs_mount_list(&mounts, errp)) { return NULL; } -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> This a more accurate way to lookup the test data, and will allow to move the test in a subproject. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/unit/test-qga.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_get_osinfo(gconstpointer data) { TestFixture fixture; const gchar *str; - gchar *cwd, *env[2]; - QDict *ret, *val; + QDict *ret = NULL; + char *env[2]; + QDict *val; - cwd = g_get_current_dir(); env[0] = g_strdup_printf( - "QGA_OS_RELEASE=%s%ctests%cdata%ctest-qga-os-release", - cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); + "QGA_OS_RELEASE=%s%c..%cdata%ctest-qga-os-release", + g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); env[1] = NULL; - g_free(cwd); fixture_setup(&fixture, NULL, env); ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}"); -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> No need to setup an environment or to check if the variable is undefined manually. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- qga/installer/qemu-ga.wxs | 30 +++++++++--------------------- qga/meson.build | 9 ++++----- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index XXXXXXX..XXXXXXX 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -XXX,XX +XXX,XX @@ <?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> - <?ifndef env.QEMU_GA_VERSION ?> - <?error Environment variable QEMU_GA_VERSION undefined?> - <?endif?> - - <?ifndef env.QEMU_GA_DISTRO ?> - <?error Environment variable QEMU_GA_DISTRO undefined?> - <?endif?> - - <?ifndef env.QEMU_GA_MANUFACTURER ?> - <?error Environment variable QEMU_GA_MANUFACTURER undefined?> - <?endif?> - <?ifndef var.Arch?> <?error Define Arch to 32 or 64?> <?endif?> @@ -XXX,XX +XXX,XX @@ Name="QEMU guest agent" Id="*" UpgradeCode="{EB6B8302-C06E-4BEC-ADAC-932C68A3A98D}" - Manufacturer="$(env.QEMU_GA_MANUFACTURER)" - Version="$(env.QEMU_GA_VERSION)" + Manufacturer="$(var.QEMU_GA_MANUFACTURER)" + Version="$(var.QEMU_GA_VERSION)" Language="1033"> <?if $(var.Arch) = 32 ?> <Condition Message="Error: 32-bit version of Qemu GA can not be installed on 64-bit Windows.">NOT VersionNT64</Condition> <?endif?> <Package - Manufacturer="$(env.QEMU_GA_MANUFACTURER)" + Manufacturer="$(var.QEMU_GA_MANUFACTURER)" InstallerVersion="200" Languages="1033" Compressed="yes" InstallScope="perMachine" /> - <Media Id="1" Cabinet="qemu_ga.$(env.QEMU_GA_VERSION).cab" EmbedCab="yes" /> + <Media Id="1" Cabinet="qemu_ga.$(var.QEMU_GA_VERSION).cab" EmbedCab="yes" /> <Property Id="WHSLogo">1</Property> <MajorUpgrade DowngradeErrorMessage="Error: A newer version of QEMU guest agent is already installed." @@ -XXX,XX +XXX,XX @@ <Directory Id="$(var.GaProgramFilesFolder)" Name="QEMU Guest Agent"> <Directory Id="qemu_ga_directory" Name="Qemu-ga"> <Component Id="qemu_ga" Guid="{908B7199-DE2A-4DC6-A8D0-27A5AE444FEA}"> - <File Id="qemu_ga.exe" Name="qemu-ga.exe" Source="$(env.BUILD_DIR)/qga/qemu-ga.exe" KeyPath="yes" DiskId="1"/> + <File Id="qemu_ga.exe" Name="qemu-ga.exe" Source="$(var.BUILD_DIR)/qga/qemu-ga.exe" KeyPath="yes" DiskId="1"/> <ServiceInstall Id="ServiceInstaller" Type="ownProcess" @@ -XXX,XX +XXX,XX @@ <File Id="libstdc++-6.lib" Name="libstdc++-6.dll" Source="$(var.Mingw_bin)/libstdc++-6.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}"> - <File Id="qga_vss.dll" Name="qga-vss.dll" Source="$(env.BUILD_DIR)/qga/vss-win32/qga-vss.dll" KeyPath="yes" DiskId="1"/> + <File Id="qga_vss.dll" Name="qga-vss.dll" Source="$(var.BUILD_DIR)/qga/vss-win32/qga-vss.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="qga_vss_tlb" Guid="{D8D584B1-59C2-4FB7-A91F-636FF7BFA66E}"> - <File Id="qga_vss.tlb" Name="qga-vss.tlb" Source="$(env.BUILD_DIR)/qga/vss-win32/qga-vss.tlb" KeyPath="yes" DiskId="1"/> + <File Id="qga_vss.tlb" Name="qga-vss.tlb" Source="$(var.BUILD_DIR)/qga/vss-win32/qga-vss.tlb" KeyPath="yes" DiskId="1"/> </Component> <?endif?> <?if $(var.Arch) = "32"?> @@ -XXX,XX +XXX,XX @@ </Component> <Component Id="registry_entries" Guid="{D075D109-51CA-11E3-9F8B-000C29858960}"> <RegistryKey Root="HKLM" - Key="Software\$(env.QEMU_GA_MANUFACTURER)\$(env.QEMU_GA_DISTRO)\Tools\QemuGA"> + Key="Software\$(var.QEMU_GA_MANUFACTURER)\$(var.QEMU_GA_DISTRO)\Tools\QemuGA"> <RegistryValue Type="string" Name="ProductID" Value="fb0a0d66-c7fb-4e2e-a16b-c4a3bfe8d13b" /> - <RegistryValue Type="string" Name="Version" Value="$(env.QEMU_GA_VERSION)" /> + <RegistryValue Type="string" Name="Version" Value="$(var.QEMU_GA_VERSION)" /> </RegistryKey> </Component> </Directory> diff --git a/qga/meson.build b/qga/meson.build index XXXXXXX..XXXXXXX 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -XXX,XX +XXX,XX @@ if targetos == 'windows' output: 'qemu-ga-@0@.msi'.format(host_arch), depends: deps, command: [ - find_program('env'), - 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'], - 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'], - 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'], - 'BUILD_DIR=' + meson.build_root(), wixl, '-o', '@OUTPUT0@', '@INPUT0@', qemu_ga_msi_arch[cpu], qemu_ga_msi_vss, + '-D', 'BUILD_DIR=' + meson.build_root(), '-D', 'Mingw_bin=' + config_host['QEMU_GA_MSI_MINGW_BIN_PATH'], + '-D', 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'], + '-D', 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'], + '-D', 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'], ]) all_qga += [qga_msi] alias_target('msi', qga_msi) -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> No clear reason to make guesses here. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- qga/installer/qemu-ga.wxs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index XXXXXXX..XXXXXXX 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -XXX,XX +XXX,XX @@ <?error Define Arch to 32 or 64?> <?endif?> - <?ifndef var.Mingw_bin?> - <?if $(var.Arch) = "64"?> - <?define Mingw_bin=/usr/x86_64-w64-mingw32/sys-root/mingw/bin ?> - <?endif?> - <?if $(var.Arch) = "32"?> - <?define Mingw_bin=/usr/i686-w64-mingw32/sys-root/mingw/bin ?> - <?endif?> - <?endif?> - <?if $(var.Arch) = "64"?> <?define ArchLib=libgcc_s_seh-1.dll?> <?define GaProgramFilesFolder="ProgramFiles64Folder" ?> -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Sadly, wixl doesn't have 'elif'. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- qga/installer/qemu-ga.wxs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index XXXXXXX..XXXXXXX 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -XXX,XX +XXX,XX @@ <?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> - <?ifndef var.Arch?> - <?error Define Arch to 32 or 64?> - <?endif?> - <?if $(var.Arch) = "64"?> <?define ArchLib=libgcc_s_seh-1.dll?> <?define GaProgramFilesFolder="ProgramFiles64Folder" ?> - <?endif?> - - <?if $(var.Arch) = "32"?> - <?define ArchLib=libgcc_s_dw2-1.dll?> - <?define GaProgramFilesFolder="ProgramFilesFolder" ?> - <?endif?> - - <?ifndef var.ArchLib ?> - <?error Unexpected Arch value $(var.Arch)?> + <?else?> + <?if $(var.Arch) = "32"?> + <?define ArchLib=libgcc_s_dw2-1.dll?> + <?define GaProgramFilesFolder="ProgramFilesFolder" ?> + <?else?> + <?error Unexpected Arch value $(var.Arch)?> + <?endif?> <?endif?> <Product -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Use more conventional variables to set the location of pre-built DLL/bin. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- configure | 9 ++++++--- meson.build | 5 ++++- qga/installer/qemu-ga.wxs | 24 ++++++++++++------------ qga/meson.build | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/configure b/configure index XXXXXXX..XXXXXXX 100755 --- a/configure +++ b/configure @@ -XXX,XX +XXX,XX @@ for i in $glib_modules; do fi done +glib_bindir="$($pkg_config --variable=bindir glib-2.0)" +if test -z "$glib_bindir" ; then + glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin +fi + # This workaround is required due to a bug in pkg-config file for glib as it # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static @@ -XXX,XX +XXX,XX @@ if test "$QEMU_GA_VERSION" = ""; then QEMU_GA_VERSION=$(cat $source_path/VERSION) fi -QEMU_GA_MSI_MINGW_BIN_PATH="$($pkg_config --variable=prefix glib-2.0)/bin" - # Mac OS X ships with a broken assembler roms= if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \ @@ -XXX,XX +XXX,XX @@ if test "$debug_tcg" = "yes" ; then fi if test "$mingw32" = "yes" ; then echo "CONFIG_WIN32=y" >> $config_host_mak - echo "QEMU_GA_MSI_MINGW_BIN_PATH=${QEMU_GA_MSI_MINGW_BIN_PATH}" >> $config_host_mak echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak @@ -XXX,XX +XXX,XX @@ echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak echo "GLIB_LIBS=$glib_libs" >> $config_host_mak +echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak diff --git a/meson.build b/meson.build index XXXXXXX..XXXXXXX 100644 --- a/meson.build +++ b/meson.build @@ -XXX,XX +XXX,XX @@ add_project_arguments(config_host['GLIB_CFLAGS'].split(), native: false, language: ['c', 'cpp', 'objc']) glib = declare_dependency(compile_args: config_host['GLIB_CFLAGS'].split(), link_args: config_host['GLIB_LIBS'].split(), - version: config_host['GLIB_VERSION']) + version: config_host['GLIB_VERSION'], + variables: { + 'bindir': config_host['GLIB_BINDIR'], + }) # override glib dep with the configure results (for subprojects) meson.override_dependency('glib-2.0', glib) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index XXXXXXX..XXXXXXX 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -XXX,XX +XXX,XX @@ </Component> <?ifdef var.InstallVss?> <Component Id="libstdc++_6_lib" Guid="{55E737B5-9127-4A11-9FC3-A29367714574}"> - <File Id="libstdc++-6.lib" Name="libstdc++-6.dll" Source="$(var.Mingw_bin)/libstdc++-6.dll" KeyPath="yes" DiskId="1"/> + <File Id="libstdc++-6.lib" Name="libstdc++-6.dll" Source="$(var.BIN_DIR)/libstdc++-6.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}"> <File Id="qga_vss.dll" Name="qga-vss.dll" Source="$(var.BUILD_DIR)/qga/vss-win32/qga-vss.dll" KeyPath="yes" DiskId="1"/> @@ -XXX,XX +XXX,XX @@ <?endif?> <?if $(var.Arch) = "32"?> <Component Id="gspawn-helper-console" Guid="{446185B3-87BE-43D2-96B8-0FEFD9E8696D}"> - <File Id="gspawn-win32-helper-console.exe" Name="gspawn-win32-helper-console.exe" Source="$(var.Mingw_bin)/gspawn-win32-helper-console.exe" KeyPath="yes" DiskId="1"/> + <File Id="gspawn-win32-helper-console.exe" Name="gspawn-win32-helper-console.exe" Source="$(var.BIN_DIR)/gspawn-win32-helper-console.exe" KeyPath="yes" DiskId="1"/> </Component> <Component Id="gspawn-helper" Guid="{CD67A5A3-2DB1-4DA1-A67A-8D71E797B466}"> - <File Id="gspawn-win32-helper.exe" Name="gspawn-win32-helper.exe" Source="$(var.Mingw_bin)/gspawn-win32-helper-console.exe" KeyPath="yes" DiskId="1"/> + <File Id="gspawn-win32-helper.exe" Name="gspawn-win32-helper.exe" Source="$(var.BIN_DIR)/gspawn-win32-helper-console.exe" KeyPath="yes" DiskId="1"/> </Component> <?endif?> <?if $(var.Arch) = "64"?> <Component Id="gspawn-helper-console" Guid="{9E615A9F-349A-4992-A5C2-C10BAD173660}"> - <File Id="gspawn-win64-helper-console.exe" Name="gspawn-win64-helper-console.exe" Source="$(var.Mingw_bin)/gspawn-win64-helper-console.exe" KeyPath="yes" DiskId="1"/> + <File Id="gspawn-win64-helper-console.exe" Name="gspawn-win64-helper-console.exe" Source="$(var.BIN_DIR)/gspawn-win64-helper-console.exe" KeyPath="yes" DiskId="1"/> </Component> <Component Id="gspawn-helper" Guid="{D201AD22-1846-4E4F-B6E1-C7A908ED2457}"> - <File Id="gspawn-win64-helper.exe" Name="gspawn-win64-helper.exe" Source="$(var.Mingw_bin)/gspawn-win64-helper-console.exe" KeyPath="yes" DiskId="1"/> + <File Id="gspawn-win64-helper.exe" Name="gspawn-win64-helper.exe" Source="$(var.BIN_DIR)/gspawn-win64-helper-console.exe" KeyPath="yes" DiskId="1"/> </Component> <?endif?> <Component Id="iconv" Guid="{35EE3558-D34B-4F0A-B8BD-430FF0775246}"> - <File Id="iconv.dll" Name="iconv.dll" Source="$(var.Mingw_bin)/iconv.dll" KeyPath="yes" DiskId="1"/> + <File Id="iconv.dll" Name="iconv.dll" Source="$(var.BIN_DIR)/iconv.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libgcc_arch_lib" Guid="{ADD4D07D-4515-4AB6-AF3E-C904961B4BB0}"> - <File Id="libgcc_arch_lib" Name="$(var.ArchLib)" Source="$(var.Mingw_bin)/$(var.ArchLib)" KeyPath="yes" DiskId="1"/> + <File Id="libgcc_arch_lib" Name="$(var.ArchLib)" Source="$(var.BIN_DIR)/$(var.ArchLib)" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libglib" Guid="{D31BFD83-2773-4B65-B45A-E0D2ADA58679}"> - <File Id="libglib_2.0_0.dll" Name="libglib-2.0-0.dll" Source="$(var.Mingw_bin)/libglib-2.0-0.dll" KeyPath="yes" DiskId="1"/> + <File Id="libglib_2.0_0.dll" Name="libglib-2.0-0.dll" Source="$(var.BIN_DIR)/libglib-2.0-0.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libintl" Guid="{A641BC2D-A907-4A94-9149-F30ED430878F}"> - <File Id="libintl_8.dll" Name="libintl-8.dll" Source="$(var.Mingw_bin)/libintl-8.dll" KeyPath="yes" DiskId="1"/> + <File Id="libintl_8.dll" Name="libintl-8.dll" Source="$(var.BIN_DIR)/libintl-8.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libssp" Guid="{7880087B-02B4-4EF6-A5D3-D18F8E3D90E1}"> - <File Id="libssp_0.dll" Name="libssp-0.dll" Source="$(var.Mingw_bin)/libssp-0.dll" KeyPath="yes" DiskId="1"/> + <File Id="libssp_0.dll" Name="libssp-0.dll" Source="$(var.BIN_DIR)/libssp-0.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libwinpthread" Guid="{6C117C78-0F47-4B07-8F34-6BEE11643829}"> - <File Id="libwinpthread_1.dll" Name="libwinpthread-1.dll" Source="$(var.Mingw_bin)/libwinpthread-1.dll" KeyPath="yes" DiskId="1"/> + <File Id="libwinpthread_1.dll" Name="libwinpthread-1.dll" Source="$(var.BIN_DIR)/libwinpthread-1.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="libpcre" Guid="{7A86B45E-A009-489A-A849-CE3BACF03CD0}"> - <File Id="libpcre_1.dll" Name="libpcre-1.dll" Source="$(var.Mingw_bin)/libpcre-1.dll" KeyPath="yes" DiskId="1"/> + <File Id="libpcre_1.dll" Name="libpcre-1.dll" Source="$(var.BIN_DIR)/libpcre-1.dll" KeyPath="yes" DiskId="1"/> </Component> <Component Id="registry_entries" Guid="{D075D109-51CA-11E3-9F8B-000C29858960}"> <RegistryKey Root="HKLM" diff --git a/qga/meson.build b/qga/meson.build index XXXXXXX..XXXXXXX 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -XXX,XX +XXX,XX @@ if targetos == 'windows' qemu_ga_msi_arch[cpu], qemu_ga_msi_vss, '-D', 'BUILD_DIR=' + meson.build_root(), - '-D', 'Mingw_bin=' + config_host['QEMU_GA_MSI_MINGW_BIN_PATH'], + '-D', 'BIN_DIR=' + glib.get_variable('bindir'), '-D', 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'], '-D', 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'], '-D', 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'], -- 2.36.1
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- tests/unit/test-qga.c | 121 +++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 78 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index XXXXXXX..XXXXXXX 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -XXX,XX +XXX,XX @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) { const gchar *extra_arg = data; GError *error = NULL; - gchar *cwd, *path, *cmd, **argv = NULL; + g_autofree char *cwd = NULL; + g_autofree char *path = NULL; + g_autofree char *cmd = NULL; + g_auto(GStrv) argv = NULL; fixture->loop = g_main_loop_new(NULL, FALSE); @@ -XXX,XX +XXX,XX @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) fixture->fd = connect_qga(path); g_assert_cmpint(fixture->fd, !=, -1); - - g_strfreev(argv); - g_free(cmd); - g_free(cwd); - g_free(path); } static void fixture_tear_down(TestFixture *fixture, gconstpointer data) { - gchar *tmp; + g_autofree char *tmp = NULL; kill(fixture->pid, SIGTERM); @@ -XXX,XX +XXX,XX @@ fixture_tear_down(TestFixture *fixture, gconstpointer data) tmp = g_build_filename(fixture->test_dir, "sock", NULL); g_unlink(tmp); - g_free(tmp); g_rmdir(fixture->test_dir); g_free(fixture->test_dir); @@ -XXX,XX +XXX,XX @@ static void qmp_assertion_message_error(const char *domain, QDict *dict) { const char *class, *desc; - char *s; + g_autofree char *s = NULL; QDict *error; error = qdict_get_qdict(dict, "error"); @@ -XXX,XX +XXX,XX @@ static void qmp_assertion_message_error(const char *domain, s = g_strdup_printf("assertion failed %s: %s %s", expr, class, desc); g_assertion_message(domain, file, line, func, s); - g_free(s); } #define qmp_assert_no_error(err) do { \ @@ -XXX,XX +XXX,XX @@ static void test_qga_sync_delimited(gconstpointer fix) const TestFixture *fixture = fix; guint32 v, r = g_test_rand_int(); unsigned char c; - QDict *ret; + g_autoptr(QDict) ret = NULL; qmp_fd_send_raw(fixture->fd, "\xff"); qmp_fd_send(fixture->fd, @@ -XXX,XX +XXX,XX @@ static void test_qga_sync_delimited(gconstpointer fix) v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); - - qobject_unref(ret); } static void test_qga_sync(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_test_rand_int(); - QDict *ret; + g_autoptr(QDict) ret = NULL; /* * TODO guest-sync is inherently limited: we cannot distinguish @@ -XXX,XX +XXX,XX @@ static void test_qga_sync(gconstpointer fix) v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); - - qobject_unref(ret); } static void test_qga_ping(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); - - qobject_unref(ret); } static void test_qga_id(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); g_assert_cmpint(qdict_get_int(ret, "id"), ==, 1); - - qobject_unref(ret); } static void test_qga_invalid_oob(gconstpointer fix) @@ -XXX,XX +XXX,XX @@ static void test_qga_invalid_oob(gconstpointer fix) static void test_qga_invalid_args(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', " @@ -XXX,XX +XXX,XX @@ static void test_qga_invalid_args(gconstpointer fix) g_assert_cmpstr(class, ==, "GenericError"); g_assert_cmpstr(desc, ==, "Parameter 'foo' is unexpected"); - - qobject_unref(ret); } static void test_qga_invalid_cmd(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; ret = qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_invalid_cmd(gconstpointer fix) g_assert_cmpstr(class, ==, "CommandNotFound"); g_assert_cmpint(strlen(desc), >, 0); - - qobject_unref(ret); } static void test_qga_info(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; const gchar *version; ret = qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_info(gconstpointer fix) val = qdict_get_qdict(ret, "return"); version = qdict_get_try_str(val, "version"); g_assert_cmpstr(version, ==, QEMU_VERSION); - - qobject_unref(ret); } static void test_qga_get_vcpus(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -XXX,XX +XXX,XX @@ static void test_qga_get_vcpus(gconstpointer fix) entry = qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); - - qobject_unref(ret); } static void test_qga_get_fsinfo(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -XXX,XX +XXX,XX @@ static void test_qga_get_fsinfo(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk")); } - - qobject_unref(ret); } static void test_qga_get_memory_block_info(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; int64_t size; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_get_memory_block_info(gconstpointer fix) size = qdict_get_int(val, "size"); g_assert_cmpint(size, >, 0); } - - qobject_unref(ret); } static void test_qga_get_memory_blocks(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -XXX,XX +XXX,XX @@ static void test_qga_get_memory_blocks(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); } } - - qobject_unref(ret); } static void test_qga_network_get_interfaces(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -XXX,XX +XXX,XX @@ static void test_qga_network_get_interfaces(gconstpointer fix) list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); - - qobject_unref(ret); } static void test_qga_file_ops(gconstpointer fix) @@ -XXX,XX +XXX,XX @@ static void test_qga_file_write_read(gconstpointer fix) static void test_qga_get_time(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; int64_t time; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_get_time(gconstpointer fix) time = qdict_get_int(ret, "return"); g_assert_cmpint(time, >, 0); - - qobject_unref(ret); } static void test_qga_blacklist(gconstpointer data) @@ -XXX,XX +XXX,XX @@ static void test_qga_blacklist(gconstpointer data) static void test_qga_config(gconstpointer data) { GError *error = NULL; - char *cwd, *cmd, *out, *err, *str, **strv, **argv = NULL; + g_autofree char *out = NULL; + g_autofree char *err = NULL; + g_autofree char *cwd = NULL; + g_autofree char *cmd = NULL; + g_auto(GStrv) argv = NULL; + g_auto(GStrv) strv = NULL; + g_autoptr(GKeyFile) kf = NULL; + char *str; char *env[2]; int status; gsize n; - GKeyFile *kf; cwd = g_get_current_dir(); cmd = g_strdup_printf("%s%cqga%cqemu-ga -D", cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR); - g_free(cwd); g_shell_parse_argv(cmd, NULL, &argv, &error); - g_free(cmd); g_assert_no_error(error); env[0] = g_strdup_printf("QGA_CONF=tests%cdata%ctest-qga-config", @@ -XXX,XX +XXX,XX @@ static void test_qga_config(gconstpointer data) env[1] = NULL; g_spawn_sync(NULL, argv, env, 0, NULL, NULL, &out, &err, &status, &error); - g_strfreev(argv); g_assert_no_error(error); g_assert_cmpstr(err, ==, ""); @@ -XXX,XX +XXX,XX @@ static void test_qga_config(gconstpointer data) g_assert_true(g_strv_contains((const char * const *)strv, "guest-get-time")); g_assert_no_error(error); - g_strfreev(strv); - g_free(out); - g_free(err); g_free(env[0]); - g_key_file_free(kf); } static void test_qga_fsfreeze_status(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; const gchar *status; ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_fsfreeze_status(gconstpointer fix) status = qdict_get_try_str(ret, "return"); g_assert_cmpstr(status, ==, "thawed"); - - qobject_unref(ret); } static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; const gchar *out; - guchar *decoded; + g_autofree guchar *decoded = NULL; int64_t pid, now, exitcode; gsize len; bool exited; @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_exec(gconstpointer fix) decoded = g_base64_decode(out, &len); g_assert_cmpint(len, ==, 12); g_assert_cmpstr((char *)decoded, ==, "\" test_str \""); - g_free(decoded); - qobject_unref(ret); } static void test_qga_guest_exec_invalid(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; /* invalid command */ @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_exec_invalid(gconstpointer fix) desc = qdict_get_str(error, "desc"); g_assert_cmpstr(class, ==, "GenericError"); g_assert_cmpint(strlen(desc), >, 0); - qobject_unref(ret); } static void test_qga_guest_get_host_name(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-host-name'}"); g_assert_nonnull(ret); @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_get_host_name(gconstpointer fix) val = qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "host-name")); - - qobject_unref(ret); } static void test_qga_guest_get_timezone(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-timezone'}"); g_assert_nonnull(ret); @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_get_timezone(gconstpointer fix) /* Make sure there's at least offset */ val = qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "offset")); - - qobject_unref(ret); } static void test_qga_guest_get_users(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-users'}"); @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_get_users(gconstpointer fix) /* There is not much to test here */ val = qdict_get_qlist(ret, "return"); g_assert_nonnull(val); - - qobject_unref(ret); } static void test_qga_guest_get_osinfo(gconstpointer data) { TestFixture fixture; const gchar *str; - QDict *ret = NULL; + g_autoptr(QDict) ret = NULL; char *env[2]; QDict *val; @@ -XXX,XX +XXX,XX @@ static void test_qga_guest_get_osinfo(gconstpointer data) g_assert_nonnull(str); g_assert_cmpstr(str, ==, "unit-test"); - qobject_unref(ret); g_free(env[0]); fixture_tear_down(&fixture, NULL); } -- 2.36.1