summaryrefslogtreecommitdiffstats
path: root/monitor
diff options
context:
space:
mode:
authorKevin Wolf2020-01-29 11:22:36 +0100
committerMarkus Armbruster2020-02-17 13:47:48 +0100
commitc3e9555182edc8766d67d2f4471774e2aac0500a (patch)
tree9fdab35d112e1d06a597bd41d05a3a5ef31fd955 /monitor
parentMerge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-02-15' into ... (diff)
downloadqemu-c3e9555182edc8766d67d2f4471774e2aac0500a.tar.gz
qemu-c3e9555182edc8766d67d2f4471774e2aac0500a.tar.xz
qemu-c3e9555182edc8766d67d2f4471774e2aac0500a.zip
monitor: Move monitor option parsing to monitor/monitor.c
Both the system emulators and tools with QMP support (specifically, the planned storage daemon) will need to parse monitor options, so move that code to monitor/monitor.c, which can be linked into binaries that aren't a system emulator. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200129102239.31435-2-kwolf@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r--monitor/monitor.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 12898b6448..c1a6c4460f 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -609,6 +609,54 @@ void monitor_init_globals_core(void)
NULL);
}
+int monitor_init_opts(QemuOpts *opts, Error **errp)
+{
+ Chardev *chr;
+ bool qmp;
+ bool pretty = false;
+ const char *chardev;
+ const char *mode;
+
+ mode = qemu_opt_get(opts, "mode");
+ if (mode == NULL) {
+ mode = "readline";
+ }
+ if (strcmp(mode, "readline") == 0) {
+ qmp = false;
+ } else if (strcmp(mode, "control") == 0) {
+ qmp = true;
+ } else {
+ error_setg(errp, "unknown monitor mode \"%s\"", mode);
+ return -1;
+ }
+
+ if (!qmp && qemu_opt_get(opts, "pretty")) {
+ warn_report("'pretty' is deprecated for HMP monitors, it has no effect "
+ "and will be removed in future versions");
+ }
+ if (qemu_opt_get_bool(opts, "pretty", 0)) {
+ pretty = true;
+ }
+
+ chardev = qemu_opt_get(opts, "chardev");
+ if (!chardev) {
+ error_report("chardev is required");
+ exit(1);
+ }
+ chr = qemu_chr_find(chardev);
+ if (chr == NULL) {
+ error_setg(errp, "chardev \"%s\" not found", chardev);
+ return -1;
+ }
+
+ if (qmp) {
+ monitor_init_qmp(chr, pretty);
+ } else {
+ monitor_init_hmp(chr, true);
+ }
+ return 0;
+}
+
QemuOptsList qemu_mon_opts = {
.name = "mon",
.implied_opt_name = "chardev",