chardev: Add -qmp-pretty

Add a command line option for adding a QMP monitor using pretty JSON
formatting.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Max Reitz 2014-11-17 13:31:04 +01:00 committed by Kevin Wolf
parent 4b58554a0e
commit 4821cd4cfd
2 changed files with 18 additions and 5 deletions

View File

@ -2790,6 +2790,14 @@ STEXI
@findex -qmp @findex -qmp
Like -monitor but opens in 'control' mode. Like -monitor but opens in 'control' mode.
ETEXI ETEXI
DEF("qmp-pretty", HAS_ARG, QEMU_OPTION_qmp_pretty, \
"-qmp-pretty dev like -qmp but uses pretty JSON formatting\n",
QEMU_ARCH_ALL)
STEXI
@item -qmp-pretty @var{dev}
@findex -qmp-pretty
Like -qmp but uses pretty JSON formatting.
ETEXI
DEF("mon", HAS_ARG, QEMU_OPTION_mon, \ DEF("mon", HAS_ARG, QEMU_OPTION_mon, \
"-mon [chardev=]name[,mode=readline|control][,default]\n", QEMU_ARCH_ALL) "-mon [chardev=]name[,mode=readline|control][,default]\n", QEMU_ARCH_ALL)

15
vl.c
View File

@ -2284,7 +2284,7 @@ static int mon_init_func(QemuOpts *opts, void *opaque)
return 0; return 0;
} }
static void monitor_parse(const char *optarg, const char *mode) static void monitor_parse(const char *optarg, const char *mode, bool pretty)
{ {
static int monitor_device_index = 0; static int monitor_device_index = 0;
QemuOpts *opts; QemuOpts *opts;
@ -2314,6 +2314,7 @@ static void monitor_parse(const char *optarg, const char *mode)
} }
qemu_opt_set(opts, "mode", mode); qemu_opt_set(opts, "mode", mode);
qemu_opt_set(opts, "chardev", label); qemu_opt_set(opts, "chardev", label);
qemu_opt_set_bool(opts, "pretty", pretty);
if (def) if (def)
qemu_opt_set(opts, "default", "on"); qemu_opt_set(opts, "default", "on");
monitor_device_index++; monitor_device_index++;
@ -3292,11 +3293,15 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_monitor: case QEMU_OPTION_monitor:
default_monitor = 0; default_monitor = 0;
if (strncmp(optarg, "none", 4)) { if (strncmp(optarg, "none", 4)) {
monitor_parse(optarg, "readline"); monitor_parse(optarg, "readline", false);
} }
break; break;
case QEMU_OPTION_qmp: case QEMU_OPTION_qmp:
monitor_parse(optarg, "control"); monitor_parse(optarg, "control", false);
default_monitor = 0;
break;
case QEMU_OPTION_qmp_pretty:
monitor_parse(optarg, "control", true);
default_monitor = 0; default_monitor = 0;
break; break;
case QEMU_OPTION_mon: case QEMU_OPTION_mon:
@ -3994,7 +3999,7 @@ int main(int argc, char **argv, char **envp)
add_device_config(DEV_SCLP, "stdio"); add_device_config(DEV_SCLP, "stdio");
} }
if (default_monitor) if (default_monitor)
monitor_parse("stdio", "readline"); monitor_parse("stdio", "readline", false);
} }
} else { } else {
if (default_serial) if (default_serial)
@ -4002,7 +4007,7 @@ int main(int argc, char **argv, char **envp)
if (default_parallel) if (default_parallel)
add_device_config(DEV_PARALLEL, "vc:80Cx24C"); add_device_config(DEV_PARALLEL, "vc:80Cx24C");
if (default_monitor) if (default_monitor)
monitor_parse("vc:80Cx24C", "readline"); monitor_parse("vc:80Cx24C", "readline", false);
if (default_virtcon) if (default_virtcon)
add_device_config(DEV_VIRTCON, "vc:80Cx24C"); add_device_config(DEV_VIRTCON, "vc:80Cx24C");
if (default_sclp) { if (default_sclp) {