diff mbox series

[RFC,V1,07/14] monitor: chardev name

Message ID 1729178055-207271-8-git-send-email-steven.sistare@oracle.com (mailing list archive)
State New
Headers show
Series precreate phase | expand

Commit Message

Steven Sistare Oct. 17, 2024, 3:14 p.m. UTC
Define an accessor that returns the chardev name in monitor options.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/monitor/monitor.h |  1 +
 monitor/monitor.c         | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index c3740ec..8edfd12 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -23,6 +23,7 @@  void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp);
 void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp);
 int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp);
 int monitor_init_opts(QemuOpts *opts, Error **errp);
+int monitor_chardev_name(QemuOpts *opts, char **name, Error **errp);
 void monitor_cleanup(void);
 
 int monitor_suspend(Monitor *mon);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index db52a9c..8b356b6 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -777,6 +777,27 @@  int monitor_init_opts(QemuOpts *opts, Error **errp)
     return ret;
 }
 
+int monitor_chardev_name(QemuOpts *opts, char **namep, Error **errp)
+{
+    Visitor *v = opts_visitor_new(opts);
+    MonitorOptions *options;
+
+    visit_type_MonitorOptions(v, NULL, &options, errp);
+    visit_free(v);
+    if (!options) {
+        return -1;
+    }
+
+    if (options->chardev) {
+        *namep = g_strdup(options->chardev);
+    } else {
+        *namep = NULL;
+    }
+
+    qapi_free_MonitorOptions(options);
+    return 0;
+}
+
 QemuOptsList qemu_mon_opts = {
     .name = "mon",
     .implied_opt_name = "chardev",