From: Anton Nefedov <anton.nefedov@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: den@virtuozzo.com, pbonzini@redhat.com,
marcandre.lureau@redhat.com, dgilbert@redhat.com,
Anton Nefedov <anton.nefedov@virtuozzo.com>
Subject: [Qemu-devel] [PATCH] char: don't exit on hmp 'chardev-add help'
Date: Mon, 17 Jul 2017 13:52:35 +0300 [thread overview]
Message-ID: <1500288755-76809-1-git-send-email-anton.nefedov@virtuozzo.com> (raw)
qemu_chr_new_from_opts() is used from both vl.c and hmp,
and it is quite confusing to see qemu suddenly exit after receiving a help
option in hmp.
Create a separate function for printing help and let different callers
react accordingly.
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
---
include/chardev/char.h | 9 +++++++++
chardev/char.c | 27 +++++++++++++++++++--------
vl.c | 4 ++++
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 1604ea9..461962b 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -59,6 +59,15 @@ struct Chardev {
};
/**
+ * @qemu_chr_help:
+ *
+ * Print available chardevice backends if 'asked for help' in @opts
+ *
+ * Returns: true if there was a help option
+ */
+bool qemu_chr_help(QemuOpts *opts);
+
+/**
* @qemu_chr_new_from_opts:
*
* Create a new character backend from a QemuOpts list.
diff --git a/chardev/char.c b/chardev/char.c
index c34b44a..19833fe 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -604,14 +604,9 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
return backend;
}
-Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)
+bool qemu_chr_help(QemuOpts *opts)
{
- const ChardevClass *cc;
- Chardev *chr = NULL;
- ChardevBackend *backend = NULL;
- const char *name = chardev_alias_translate(qemu_opt_get(opts, "backend"));
- const char *id = qemu_opts_id(opts);
- char *bid = NULL;
+ const char *name = qemu_opt_get(opts, "backend");
if (name && is_help_option(name)) {
GString *str = g_string_new("");
@@ -620,7 +615,23 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)
error_report("Available chardev backend types: %s", str->str);
g_string_free(str, true);
- exit(0);
+ return true;
+ }
+
+ return false;
+}
+
+Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)
+{
+ const ChardevClass *cc;
+ Chardev *chr = NULL;
+ ChardevBackend *backend = NULL;
+ const char *name = chardev_alias_translate(qemu_opt_get(opts, "backend"));
+ const char *id = qemu_opts_id(opts);
+ char *bid = NULL;
+
+ if (qemu_chr_help(opts)) {
+ return NULL;
}
if (id == NULL) {
diff --git a/vl.c b/vl.c
index fb6b2ef..7cad539 100644
--- a/vl.c
+++ b/vl.c
@@ -2344,6 +2344,10 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
Error *local_err = NULL;
+ if (qemu_chr_help(opts)) {
+ exit(0);
+ }
+
qemu_chr_new_from_opts(opts, &local_err);
if (local_err) {
error_report_err(local_err);
--
2.7.4
next reply other threads:[~2017-07-17 10:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-17 10:52 Anton Nefedov [this message]
2017-07-17 11:19 ` [Qemu-devel] [PATCH] char: don't exit on hmp 'chardev-add help' Marc-André Lureau
2017-07-24 16:50 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1500288755-76809-1-git-send-email-anton.nefedov@virtuozzo.com \
--to=anton.nefedov@virtuozzo.com \
--cc=den@virtuozzo.com \
--cc=dgilbert@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).