diff options
| author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2026-08-28 16:04:34 +0400 |
|---|---|---|
| committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2026-08-29 12:07:45 +0400 |
| commit | f3900cfb0cddd2fcc3b9db20f52f3755e6ed962f (patch) | |
| tree | 6cf4fe4278f1e3237b8fb05725a3875e4ff3a5dc /util | |
| parent | bcf97f76064885730f491b63d4543b60c87c09fd (diff) | |
| download | qemu-f3900cfb0cddd2fcc3b9db20f52f3755e6ed962f.tar.gz qemu-f3900cfb0cddd2fcc3b9db20f52f3755e6ed962f.zip | |
monitor: tighten monitor_printf*()
Rename monitor_printf->monitor_hmp_printf, monitor_vprintf->
monitor_hmp_vprintf, and monitor_printc->monitor_hmp_printc, changing
the first parameter from Monitor * to MonitorHMP * to enforce type
safety. The implementation is also simplified: monitor_hmp_vprintf now
directly calls g_strdup_vprintf + monitor_puts, removing the virtual
dispatch via moncls->vprintf.
The dev_print() callbacks are temporarily using the MONITOR_HMP(mon)
cast, they are fixed in the following commits.
Early return in qemu_vprintf() if "hmp" is NULL, relying on
monitor_hmp_vprintf() handling NULL case is a bit uncommon.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260828-qemu-no-hmp-v5-37-9227de146347@redhat.com>
Diffstat (limited to 'util')
| -rw-r--r-- | util/error-report.c | 2 | ||||
| -rw-r--r-- | util/qemu-print.c | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/util/error-report.c b/util/error-report.c index 41694d61cf..0e3aaa539e 100644 --- a/util/error-report.c +++ b/util/error-report.c @@ -36,7 +36,7 @@ static int G_GNUC_PRINTF(2, 0) error_vprintf_hmp(MonitorHMP *hmp, const char *fmt, va_list ap) { if (hmp) { - return monitor_vprintf(MONITOR(hmp), fmt, ap); + return monitor_hmp_vprintf(hmp, fmt, ap); } return vfprintf(stderr, fmt, ap); diff --git a/util/qemu-print.c b/util/qemu-print.c index 5d4143d425..01ed43b5a5 100644 --- a/util/qemu-print.c +++ b/util/qemu-print.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" #include "monitor/hmp.h" +#include "qom/object.h" #include "qemu/qemu-print.h" /* @@ -23,8 +24,16 @@ int qemu_vprintf(const char *fmt, va_list ap) { Monitor *cur_mon = monitor_cur(); + + /* for all monitors: QMP & HMP */ if (cur_mon) { - return monitor_vprintf(cur_mon, fmt, ap); + /* don't use monitor_cur_hmp(), to avoid a second lookup */ + MonitorHMP *hmp = (MonitorHMP *) + object_dynamic_cast(OBJECT(cur_mon), TYPE_MONITOR_HMP); + if (!hmp) { + return -1; + } + return monitor_hmp_vprintf(hmp, fmt, ap); } return vprintf(fmt, ap); } @@ -55,7 +64,11 @@ int qemu_printf(const char *fmt, ...) int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap) { if (!stream) { - return monitor_vprintf(monitor_cur(), fmt, ap); + MonitorHMP *hmp = monitor_cur_hmp(); + if (!hmp) { + return -1; + } + return monitor_hmp_vprintf(hmp, fmt, ap); } return vfprintf(stream, fmt, ap); } |
