提交 23802b4f 编写于 作者: F Fam Zheng 提交者: Andreas Färber

qtest: Don't segfault with invalid -qtest option

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: NFam Zheng <famz@redhat.com>
Signed-off-by: NAndreas Färber <afaerber@suse.de>
上级 1f9c4cfd
......@@ -15,6 +15,7 @@
#define QTEST_H
#include "qemu-common.h"
#include "qapi/error.h"
extern bool qtest_allowed;
......@@ -26,7 +27,7 @@ static inline bool qtest_enabled(void)
bool qtest_driver(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)
{
......
......@@ -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);
......
......@@ -4078,7 +4078,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 (local_err) {
error_report("%s", error_get_pretty(local_err));
error_free(local_err);
exit(1);
}
}
machine_opts = qemu_get_machine_opts();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册