Hi

On Mon, Aug 10, 2026 at 10:34 PM Daniel P. Berrangé <[email protected]> wrote:
>
> On Fri, Jun 26, 2026 at 01:19:32AM +0400, Marc-André Lureau wrote:
> > Guard calls to monitor_vprintf in error-report and qemu-print so
> > they compile without HMP. When CONFIG_HMP is not set,
> > error_vprintf_mon falls back directly to stderr and qemu_vfprintf
> > returns -1 for NULL streams.
> >
> > Signed-off-by: Marc-André Lureau <[email protected]>
> > ---
> >  tests/unit/test-util-sockets.c | 4 +++-
> >  tools/qemu-vnc/stubs.c         | 2 ++
> >  util/error-report.c            | 8 +++++---
> >  util/qemu-print.c              | 6 ++++++
> >  4 files changed, 16 insertions(+), 4 deletions(-)
>
> This patch probably isn't required any more.
>
> With the QOM classes for montior,  monitor_vprintf calls to a 'vprintf'
> class virtual method, or returns -1.
>
> So simply by virtue of HMP being compiled out, monitor_vprintf should
> do the right thing.

It does, but shouldn't we remove API that only works & makes sense
when HMP is enabled? The monitor_printf* functions are not just simple
stubs, but won't work without HMP. I'll try to improve this now that
we have proper objects.

>
> >
> > diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
> > index b9f2453e299..23ebe1e26b5 100644
> > --- a/tests/unit/test-util-sockets.c
> > +++ b/tests/unit/test-util-sockets.c
> > @@ -73,8 +73,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname, 
> > Error **errp)
> >   */
> >  Monitor *monitor_cur(void) { return cur_mon; }
> >  Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
> > -int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
> >  bool monitor_cur_is_qmp(void) { abort(); };
> > +#ifdef CONFIG_HMP
> > +int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
> > +#endif
> >
> >  #ifndef _WIN32
> >  static void test_socket_fd_pass_name_good(void)
> > diff --git a/tools/qemu-vnc/stubs.c b/tools/qemu-vnc/stubs.c
> > index a865ce85f04..f476dd6d956 100644
> > --- a/tools/qemu-vnc/stubs.c
> > +++ b/tools/qemu-vnc/stubs.c
> > @@ -46,10 +46,12 @@ Monitor *monitor_set_cur(Coroutine *co, Monitor *mon)
> >      return NULL;
> >  }
> >
> > +#ifdef CONFIG_HMP
> >  int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
> >  {
> >      return -1;
> >  }
> > +#endif
> >
> >  /*
> >   * Link-time stubs for VMState symbols referenced by VNC code.
> > diff --git a/util/error-report.c b/util/error-report.c
> > index f832ad9b6b6..e2e46281455 100644
> > --- a/util/error-report.c
> > +++ b/util/error-report.c
> > @@ -40,11 +40,13 @@ error_vprintf_mon(Monitor *cur_mon, const char *fmt, 
> > va_list ap)
> >       * IOW this will only print if in HMP, otherwise we
> >       * fallback to stderr for QMP / no-monitor scenarios.
> >       */
> > +#ifdef CONFIG_HMP
> >      int ret = monitor_vprintf(cur_mon, fmt, ap);
> > -    if (ret == -1) {
> > -        ret = vfprintf(stderr, fmt, ap);
> > +    if (ret != -1) {
> > +        return ret;
> >      }
> > -    return ret;
> > +#endif
> > +    return vfprintf(stderr, fmt, ap);
> >  }
> >
> >  /*
> > diff --git a/util/qemu-print.c b/util/qemu-print.c
> > index 7b9591035e5..ee80000722b 100644
> > --- a/util/qemu-print.c
> > +++ b/util/qemu-print.c
> > @@ -20,10 +20,12 @@
> >   */
> >  int qemu_vprintf(const char *fmt, va_list ap)
> >  {
> > +#ifdef CONFIG_HMP
> >      Monitor *cur_mon = monitor_cur();
> >      if (cur_mon) {
> >          return monitor_vprintf(cur_mon, fmt, ap);
> >      }
> > +#endif
> >      return vprintf(fmt, ap);
> >  }
> >
> > @@ -52,7 +54,11 @@ int qemu_printf(const char *fmt, ...)
> >  int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
> >  {
> >      if (!stream) {
> > +#ifdef CONFIG_HMP
> >          return monitor_vprintf(monitor_cur(), fmt, ap);
> > +#else
> > +        return -1;
> > +#endif
> >      }
> >      return vfprintf(stream, fmt, ap);
> >  }
> >
> > --
> > 2.54.0
> >
>
> With regards,
> Daniel
> --
> |: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
> |: https://libvirt.org          ~~          https://entangle-photo.org :|
> |: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
>


Reply via email to