Browse Source

util: don't skip error prefixes when QMP is active

The vreport() function will print to HMP if available, otherwise
to stderr. In the event that vreport() is called during execution
of a QMP command, it will print to stderr, but mistakenly omit the
message prefixes (timestamp, guest name, program name).

This new usage of monitor_is_cur_qmp() from vreport() requires that
we add a stub to satisfy linking of non-system emulator binaries.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
master
Daniel P. Berrangé 7 months ago
parent
commit
6365e97c84
  1. 5
      stubs/monitor-core.c
  2. 1
      tests/unit/test-util-sockets.c
  3. 8
      util/error-report.c

5
stubs/monitor-core.c

@ -7,6 +7,11 @@ Monitor *monitor_cur(void)
return NULL;
}
bool monitor_cur_is_qmp(void)
{
return false;
}
Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
{
return NULL;

1
tests/unit/test-util-sockets.c

@ -74,6 +74,7 @@ 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(); };
#ifndef _WIN32
static void test_socket_fd_pass_name_good(void)

8
util/error-report.c

@ -226,6 +226,14 @@ static void vreport(report_type type, const char *fmt, va_list ap)
Monitor *cur = monitor_cur();
gchar *timestr;
/*
* When current monitor is QMP, messages must go to stderr
* and have prefixes added
*/
if (monitor_cur_is_qmp()) {
cur = NULL;
}
if (message_with_timestamp && !cur) {
timestr = real_time_iso8601();
fprintf(stderr, "%s ", timestr);

Loading…
Cancel
Save