Luiz Capitulino <lcapitul...@redhat.com> writes: > Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com> > --- > monitor.c | 29 +++++++++++++++++++++++++---- > 1 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/monitor.c b/monitor.c > index 47f794d..3d33bd8 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -514,10 +514,30 @@ static void do_info_version(Monitor *mon, QObject > **ret_data) > QEMU_VERSION, QEMU_PKGVERSION); > } > > -static void do_info_name(Monitor *mon) > +static void do_info_name_print(Monitor *mon, const QObject *data) > { > - if (qemu_name) > - monitor_printf(mon, "%s\n", qemu_name); > + const char *str; > + > + str = qdict_get_str(qobject_to_qdict(data), "name"); > + if (strlen(str) > 0) { > + monitor_printf(mon, "%s\n", str); > + } > +} > + > +/** > + * do_info_name(): Show VM name > + * > + * Return a QDict with the following information: > + * > + * - "name": VM's name. If the VM has no name, the string will be empty
So you can't distinguish name "" from unnamed. Do we care? Monitor output for unnamed guests changes from (qemu) info name (qemu) to (qemu) info name (qemu) > + * > + * Example: > + * > + * { "name": "qemu-name" } > + */ > +static void do_info_name(Monitor *mon, QObject **ret_data) > +{ > + *ret_data = qobject_from_jsonf("{'name': %s}", qemu_name ? qemu_name : > ""); > } > > /** > @@ -2449,7 +2469,8 @@ static const mon_cmd_t info_cmds[] = { > .args_type = "", > .params = "", > .help = "show the current VM name", > - .mhandler.info = do_info_name, > + .user_print = do_info_name_print, > + .mhandler.info_new = do_info_name, > }, > { > .name = "uuid",