Guard calls to monitor_vprintf in error-report and qemu-print so they compile without HMP. When CONFIG_HMP is not set, error_vprintf_mon falls back directly to stderr and qemu_vfprintf returns -1 for NULL streams.
Signed-off-by: Marc-André Lureau <[email protected]> --- tests/unit/test-util-sockets.c | 4 +++- tools/qemu-vnc/stubs.c | 2 ++ util/error-report.c | 8 +++++--- util/qemu-print.c | 6 ++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index b9f2453e299..23ebe1e26b5 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -73,8 +73,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) */ Monitor *monitor_cur(void) { return cur_mon; } Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); } -int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } bool monitor_cur_is_qmp(void) { abort(); }; +#ifdef CONFIG_HMP +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); } +#endif #ifndef _WIN32 static void test_socket_fd_pass_name_good(void) diff --git a/tools/qemu-vnc/stubs.c b/tools/qemu-vnc/stubs.c index a865ce85f04..f476dd6d956 100644 --- a/tools/qemu-vnc/stubs.c +++ b/tools/qemu-vnc/stubs.c @@ -46,10 +46,12 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) return NULL; } +#ifdef CONFIG_HMP int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { return -1; } +#endif /* * Link-time stubs for VMState symbols referenced by VNC code. diff --git a/util/error-report.c b/util/error-report.c index f832ad9b6b6..e2e46281455 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -40,11 +40,13 @@ error_vprintf_mon(Monitor *cur_mon, const char *fmt, va_list ap) * IOW this will only print if in HMP, otherwise we * fallback to stderr for QMP / no-monitor scenarios. */ +#ifdef CONFIG_HMP int ret = monitor_vprintf(cur_mon, fmt, ap); - if (ret == -1) { - ret = vfprintf(stderr, fmt, ap); + if (ret != -1) { + return ret; } - return ret; +#endif + return vfprintf(stderr, fmt, ap); } /* diff --git a/util/qemu-print.c b/util/qemu-print.c index 7b9591035e5..ee80000722b 100644 --- a/util/qemu-print.c +++ b/util/qemu-print.c @@ -20,10 +20,12 @@ */ int qemu_vprintf(const char *fmt, va_list ap) { +#ifdef CONFIG_HMP Monitor *cur_mon = monitor_cur(); if (cur_mon) { return monitor_vprintf(cur_mon, fmt, ap); } +#endif return vprintf(fmt, ap); } @@ -52,7 +54,11 @@ int qemu_printf(const char *fmt, ...) int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) { if (!stream) { +#ifdef CONFIG_HMP return monitor_vprintf(monitor_cur(), fmt, ap); +#else + return -1; +#endif } return vfprintf(stream, fmt, ap); } -- 2.54.0
