summaryrefslogtreecommitdiffstats
path: root/qom/object_interfaces.c
diff options
context:
space:
mode:
authorKevin Wolf2021-02-17 14:59:06 +0100
committerKevin Wolf2021-03-19 10:17:14 +0100
commitffd58ef88c73700113e0808e8222ef4d22224f33 (patch)
tree37d81679fc757d837f9eec23e31f09d7428edae4 /qom/object_interfaces.c
parentqemu-nbd: Use user_creatable_process_cmdline() for --object (diff)
downloadqemu-ffd58ef88c73700113e0808e8222ef4d22224f33.tar.gz
qemu-ffd58ef88c73700113e0808e8222ef4d22224f33.tar.xz
qemu-ffd58ef88c73700113e0808e8222ef4d22224f33.zip
qom: Add user_creatable_add_from_str()
This is a version of user_creatable_process_cmdline() with an Error parameter that never calls exit() and is therefore usable in HMP. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qom/object_interfaces.c')
-rw-r--r--qom/object_interfaces.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index e10a5cf6f0..bc091ef429 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -292,26 +292,45 @@ static void user_creatable_print_help_from_qdict(QDict *args)
}
}
-void user_creatable_process_cmdline(const char *optarg)
+bool user_creatable_add_from_str(const char *optarg, Error **errp)
{
+ ERRP_GUARD();
QDict *args;
bool help;
Visitor *v;
ObjectOptions *options;
- args = keyval_parse(optarg, "qom-type", &help, &error_fatal);
+ args = keyval_parse(optarg, "qom-type", &help, errp);
+ if (*errp) {
+ return false;
+ }
if (help) {
user_creatable_print_help_from_qdict(args);
- exit(EXIT_SUCCESS);
+ qobject_unref(args);
+ return false;
}
v = qobject_input_visitor_new_keyval(QOBJECT(args));
- visit_type_ObjectOptions(v, NULL, &options, &error_fatal);
+ visit_type_ObjectOptions(v, NULL, &options, errp);
visit_free(v);
qobject_unref(args);
- user_creatable_add_qapi(options, &error_fatal);
+ if (*errp) {
+ goto out;
+ }
+
+ user_creatable_add_qapi(options, errp);
+out:
qapi_free_ObjectOptions(options);
+ return !*errp;
+}
+
+void user_creatable_process_cmdline(const char *optarg)
+{
+ if (!user_creatable_add_from_str(optarg, &error_fatal)) {
+ /* Help was printed */
+ exit(EXIT_SUCCESS);
+ }
}
bool user_creatable_del(const char *id, Error **errp)