From: Jan Kiszka <jan.kis...@siemens.com> This simply forwards the result of the internal vsnprintf to the callers of monitor_printf and monitor_vprintf. When invoked over a QMP session or in absence of an active monitor, -1 is returned.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- monitor.c | 23 +++++++++++++++-------- monitor.h | 4 ++-- qemu-tool.c | 6 ++++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/monitor.c b/monitor.c index 64de10a..6766e49 100644 --- a/monitor.c +++ b/monitor.c @@ -258,29 +258,36 @@ static void monitor_puts(Monitor *mon, const char *str) } } -void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { char buf[4096]; + int ret; - if (!mon) - return; - + if (!mon) { + return -1; + } mon_print_count_inc(mon); if (monitor_ctrl_mode(mon)) { - return; + return -1; } - vsnprintf(buf, sizeof(buf), fmt, ap); + ret = vsnprintf(buf, sizeof(buf), fmt, ap); monitor_puts(mon, buf); + + return ret; } -void monitor_printf(Monitor *mon, const char *fmt, ...) +int monitor_printf(Monitor *mon, const char *fmt, ...) { va_list ap; + int ret; + va_start(ap, fmt); - monitor_vprintf(mon, fmt, ap); + ret = monitor_vprintf(mon, fmt, ap); va_end(ap); + + return ret; } void monitor_print_filename(Monitor *mon, const char *filename) diff --git a/monitor.h b/monitor.h index ea15469..32c0170 100644 --- a/monitor.h +++ b/monitor.h @@ -45,8 +45,8 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, int monitor_get_fd(Monitor *mon, const char *fdname); -void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); -void monitor_printf(Monitor *mon, const char *fmt, ...) +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); +int monitor_printf(Monitor *mon, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); void monitor_print_filename(Monitor *mon, const char *filename); void monitor_flush(Monitor *mon); diff --git a/qemu-tool.c b/qemu-tool.c index b39af86..f6ce6cd 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -43,12 +43,14 @@ void monitor_set_error(Monitor *mon, QError *qerror) { } -void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { + return -1; } -void monitor_printf(Monitor *mon, const char *fmt, ...) +int monitor_printf(Monitor *mon, const char *fmt, ...) { + return -1; } void monitor_print_filename(Monitor *mon, const char *filename) -- 1.6.0.2