Skip to content

Commit

Permalink
qemu-error: remove dependency of stubs on monitor
Browse files Browse the repository at this point in the history
Leave the implementation of error_vprintf and error_vprintf_unless_qmp
(the latter now trivially wrapped by error_printf_unless_qmp) to
libqemustub.a and monitor.c.  This has two advantages: it lets us
remove the monitor_printf and monitor_vprintf stubs, and it lets
tests provide a different implementation of the functions that uses
g_test_message.

Signed-off-by: Paolo Bonzini <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
bonzini committed Nov 1, 2016
1 parent 9bc9732 commit 397d30e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
1 change: 1 addition & 0 deletions include/qemu/error-report.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void loc_set_file(const char *fname, int lno);

void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void error_set_progname(const char *argv0);
void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
Expand Down
21 changes: 21 additions & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,27 @@ static void monitor_readline_flush(void *opaque)
monitor_flush(opaque);
}

/*
* Print to current monitor if we have one, else to stderr.
* TODO should return int, so callers can calculate width, but that
* requires surgery to monitor_vprintf(). Left for another day.
*/
void error_vprintf(const char *fmt, va_list ap)
{
if (cur_mon && !monitor_cur_is_qmp()) {
monitor_vprintf(cur_mon, fmt, ap);
} else {
vfprintf(stderr, fmt, ap);
}
}

void error_vprintf_unless_qmp(const char *fmt, va_list ap)
{
if (cur_mon && !monitor_cur_is_qmp()) {
monitor_vprintf(cur_mon, fmt, ap);
}
}

static void __attribute__((constructor)) monitor_lock_init(void)
{
qemu_mutex_init(&monitor_lock);
Expand Down
2 changes: 1 addition & 1 deletion stubs/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stub-obj-y += clock-warp.o
stub-obj-y += cpu-get-clock.o
stub-obj-y += cpu-get-icount.o
stub-obj-y += dump.o
stub-obj-y += error-printf.o
stub-obj-y += fdset-add-fd.o
stub-obj-y += fdset-find-fd.o
stub-obj-y += fdset-get-fd.o
Expand All @@ -23,7 +24,6 @@ stub-obj-y += is-daemonized.o
stub-obj-y += machine-init-done.o
stub-obj-y += migr-blocker.o
stub-obj-y += mon-is-qmp.o
stub-obj-y += mon-printf.o
stub-obj-y += monitor-init.o
stub-obj-y += notify-event.o
stub-obj-y += qtest.o
Expand Down
13 changes: 13 additions & 0 deletions stubs/error-printf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/error-report.h"

void error_vprintf(const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
}

void error_vprintf_unless_qmp(const char *fmt, va_list ap)
{
error_vprintf(fmt, ap);
}
11 changes: 0 additions & 11 deletions stubs/mon-printf.c

This file was deleted.

26 changes: 3 additions & 23 deletions util/qemu-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@
#include "monitor/monitor.h"
#include "qemu/error-report.h"

/*
* Print to current monitor if we have one, else to stderr.
* TODO should return int, so callers can calculate width, but that
* requires surgery to monitor_vprintf(). Left for another day.
*/
void error_vprintf(const char *fmt, va_list ap)
{
if (cur_mon && !monitor_cur_is_qmp()) {
monitor_vprintf(cur_mon, fmt, ap);
} else {
vfprintf(stderr, fmt, ap);
}
}

/*
* Print to current monitor if we have one, else to stderr.
* TODO just like error_vprintf()
*/
void error_printf(const char *fmt, ...)
{
va_list ap;
Expand All @@ -45,11 +27,9 @@ void error_printf_unless_qmp(const char *fmt, ...)
{
va_list ap;

if (!monitor_cur_is_qmp()) {
va_start(ap, fmt);
error_vprintf(fmt, ap);
va_end(ap);
}
va_start(ap, fmt);
error_vprintf_unless_qmp(fmt, ap);
va_end(ap);
}

static Location std_loc = {
Expand Down

0 comments on commit 397d30e

Please sign in to comment.