}
/*
- * Print to current monitor if we have one, else to stderr.
+ * Print to the current human monitor if we have one, else to stderr.
*/
int error_vprintf(const char *fmt, va_list ap)
{
Monitor *cur_mon = monitor_cur();
-
- if (cur_mon && !monitor_cur_is_qmp()) {
- return monitor_vprintf(cur_mon, fmt, ap);
+ /*
+ * This will return -1 if 'cur_mon' is NULL, or is QMP.
+ * IOW this will only print if in HMP, otherwise we
+ * fallback to stderr for QMP / no-monitor scenarios.
+ */
+ int ret = monitor_vprintf(cur_mon, fmt, ap);
+ if (ret == -1) {
+ ret = vfprintf(stderr, fmt, ap);
}
- return vfprintf(stderr, fmt, ap);
+ return ret;
}
static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {