From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <afaerber@suse.de>,
"Anthony Liguori" <aliguori@amazon.com>
Subject: [Qemu-devel] [PATCH v2] qtest: Don't segfault with invalid -qtest option
Date: Mon, 10 Feb 2014 09:28:02 +0800 [thread overview]
Message-ID: <1391995682-27028-1-git-send-email-famz@redhat.com> (raw)
This prints an error message, instead of core dump, when "-qtest"
option value is invalid, e.g.:
$ ./x86_64-softmmu/qemu-system-x86_64 -qtest unknown
qemu-system-x86_64: Failed to initialize device for qtest:
"unknown"
Signed-off-by: Fam Zheng <famz@redhat.com>
---
include/sysemu/qtest.h | 3 ++-
qtest.c | 8 +++++++-
vl.c | 8 +++++++-
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index 112a661..2de61c6 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -15,6 +15,7 @@
#define QTEST_H
#include "qemu-common.h"
+#include "qapi/error.h"
extern bool qtest_allowed;
@@ -24,7 +25,7 @@ static inline bool qtest_enabled(void)
}
int qtest_init_accel(void);
-void qtest_init(const char *qtest_chrdev, const char *qtest_log);
+void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
static inline int qtest_available(void)
{
diff --git a/qtest.c b/qtest.c
index dcf1301..a4ad407 100644
--- a/qtest.c
+++ b/qtest.c
@@ -507,12 +507,18 @@ int qtest_init_accel(void)
return 0;
}
-void qtest_init(const char *qtest_chrdev, const char *qtest_log)
+void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp)
{
CharDriverState *chr;
chr = qemu_chr_new("qtest", qtest_chrdev, NULL);
+ if (chr == NULL) {
+ error_setg(errp, "Failed to initialize device for qtest: \"%s\"",
+ qtest_chrdev);
+ return;
+ }
+
qemu_chr_add_handlers(chr, qtest_can_read, qtest_read, qtest_event, chr);
qemu_chr_fe_set_echo(chr, true);
diff --git a/vl.c b/vl.c
index e2e576c..bee455d 100644
--- a/vl.c
+++ b/vl.c
@@ -4079,7 +4079,13 @@ int main(int argc, char **argv, char **envp)
configure_accelerator();
if (qtest_chrdev) {
- qtest_init(qtest_chrdev, qtest_log);
+ Error *local_err = NULL;
+ qtest_init(qtest_chrdev, qtest_log, &local_err);
+ if (error_is_set(&local_err)) {
+ error_report("%s", error_get_pretty(local_err));
+ error_free(local_err);
+ exit(1);
+ }
}
machine_opts = qemu_get_machine_opts();
--
1.8.5.4
next reply other threads:[~2014-02-10 1:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 1:28 Fam Zheng [this message]
2014-02-10 8:48 ` [Qemu-devel] [PATCH v2] qtest: Don't segfault with invalid -qtest option Markus Armbruster
2014-02-10 13:43 ` Andreas Färber
2014-02-10 14:29 ` Markus Armbruster
2014-02-10 17:31 ` Andreas Färber
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=1391995682-27028-1-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.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).