@samitouri / QOSamiQemu / commits / 972ca7f60f

util: use dynamic cast in error vreport

This eliminates a use of monitor_is_qmp() from the error reporting path. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260706135824.2623960-18-berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Daniel P. Berrangé committed Jul 6, 2026 at 14:58 UTC 972ca7f60f583d674d5a29e51a8a8f93f2c34d28
1 file changed +6 -7
util/error-report.c
+6 -7
@@ -231,16 +231,15 @@ char *real_time_iso8601(void)
231 G_GNUC_PRINTF(2, 0)
232 static void vreport(report_type type, const char *fmt, va_list ap)
233 {
234 - Monitor *cur = monitor_cur();
235 - gchar *timestr;
236 -
234 /*
235 * When current monitor is QMP, messages must go to stderr
239 - * and have prefixes added
236 + * and have prefixes added, so we cast to HMP, leaving 'cur'
237 + * as NULL in QMP case
238 */
241 - if (monitor_cur_is_qmp()) {
242 - cur = NULL;
243 - }
239 + Monitor *cur = MONITOR(
240 + object_dynamic_cast(OBJECT(monitor_cur()), TYPE_MONITOR_HMP));
241 + gchar *timestr;
242 +
243 if (!cur) {
244 qemu_flockfile(stderr);
245 }