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>
This commit is contained in:
Daniel P. Berrangé
2025-09-10 17:25:59 +01:00
parent 2eb00abcfe
commit 6365e97c84
3 changed files with 14 additions and 0 deletions

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);