@samitouri / QOSamiQemu / commits / 6365e97c84

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>

Daniel P. Berrangé committed Sep 10, 2025 at 17:25 UTC 6365e97c841e43dc6ea256857ddc7e850d5c67dd
3 files changed +14
stubs/monitor-core.c
+5
@@ -7,6 +7,11 @@ Monitor *monitor_cur(void)
7 return NULL;
8 }
9
10 +bool monitor_cur_is_qmp(void)
11 +{
12 + return false;
13 +}
14 +
15 Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
16 {
17 return NULL;
tests/unit/test-util-sockets.c
+1
@@ -74,6 +74,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
74 Monitor *monitor_cur(void) { return cur_mon; }
75 Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
76 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
77 +bool monitor_cur_is_qmp(void) { abort(); };
78
79 #ifndef _WIN32
80 static void test_socket_fd_pass_name_good(void)
util/error-report.c
+8
@@ -226,6 +226,14 @@ static void vreport(report_type type, const char *fmt, va_list ap)
226 Monitor *cur = monitor_cur();
227 gchar *timestr;
228
229 + /*
230 + * When current monitor is QMP, messages must go to stderr
231 + * and have prefixes added
232 + */
233 + if (monitor_cur_is_qmp()) {
234 + cur = NULL;
235 + }
236 +
237 if (message_with_timestamp && !cur) {
238 timestr = real_time_iso8601();
239 fprintf(stderr, "%s ", timestr);