From: "john.liuli" <john.liuli@huawei.com>
To: armbru@redhat.com
Cc: qemu-trivial@nongnu.org, Li Liu <john.liuli@huawei.com>,
peter.huangpeng@huawei.com, kraxel@redhat.com,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
Date: Tue, 9 Sep 2014 19:19:48 +0800 [thread overview]
Message-ID: <1410261588-8360-1-git-send-email-john.liuli@huawei.com> (raw)
From: Li Liu <john.liuli@huawei.com>
Eeay to reproduce, just try "qemu -monitor stdio -nographic"
and type "quit", then the terminal will be crashed.
There are two pathes try to call tcgetattr of stdio in vl.c:
1) Monitor_parse(optarg, "readline");
.....
qemu_opts_foreach(qemu_find_opts("chardev"),
chardev_init_func, NULL, 1) != 0)
2) if (default_serial)
add_device_config(DEV_SERIAL, "stdio");
....
if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
Both of them will trigger qemu_chr_open_stdio which will disable
ECHO attributes. First one has updated the attributes of stdio
by calling qemu_chr_fe_set_echo(chr, false). And the tty
attributes has been saved in oldtty. Then the second path will
redo such actions, and the oldtty is overlapped. So till "quit",
term_exit can't recove the correct attributes.
Signed-off-by: Li Liu <john.liuli@huawei.com>
---
changes v1 -> v2:
1) as Markus Armbruster and Gerd Hoffmann suggested :
Multiple character devices can't use the same terminal.
So catch and reject the attempt if stdio is opened already.
---
qemu-char.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/qemu-char.c b/qemu-char.c
index d4f327a..f8f0c48 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1017,6 +1017,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
/* init terminal so that we can grab keys */
static struct termios oldtty;
static int old_fd0_flags;
+static bool stdio_is_ready;
static bool stdio_allow_signal;
static void term_exit(void)
@@ -1060,8 +1061,15 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
error_report("cannot use stdio with -daemonize");
return NULL;
}
+
+ if (stdio_is_ready) {
+ error_report("cannot use stdio by multiple character devices");
+ exit(1);
+ }
+
+ stdio_is_ready = true;
old_fd0_flags = fcntl(0, F_GETFL);
- tcgetattr (0, &oldtty);
+ tcgetattr(0, &oldtty);
qemu_set_nonblock(0);
atexit(term_exit);
--
1.7.9.5
next reply other threads:[~2014-09-09 11:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 11:19 john.liuli [this message]
2014-09-15 12:50 ` [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic" Michael Tokarev
2014-09-15 12:57 ` Michael Tokarev
2014-09-15 13:29 ` Gerd Hoffmann
2014-09-15 13:33 ` Markus Armbruster
2014-09-16 1:40 ` Li Liu
2014-09-16 4:20 ` Michael Tokarev
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=1410261588-8360-1-git-send-email-john.liuli@huawei.com \
--to=john.liuli@huawei.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@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).