qemu-char: fix terminal crash when using "-monitor stdio -nographic"
PATCH v2 1/1 qemu-char: fix terminal crash when using "-monitor stdio -nographic"
From: Li Liu <[email protected]>
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.
---
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(-)
qemu-char.c +9 -1
@@ -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);
Signature · 1 line
1.7.9.5
Quoted 6 lines · john.liuli
From: Li Liu <[email protected]>
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:
This looks reasonable. Except of one thing -- how about renaming stdio_is_ready to stdio_in_use? (I can do that when applying, no need to resend anythnig). Because, well, stdio_is_ready is not obvious at all, at least to me... :)
Thank you for fixing this!
/mjt
15.09.2014 16:50, Michael Tokarev пишет:
Quoted 6 lines
Quoted 5 lines · john.liuli
From: Li Liu <[email protected]>
Eeay to reproduce, just try "qemu -monitor stdio -nographic" and type "quit", then the terminal will be crashed.
Quoted 6 lines
Quoted 1 line
There are two pathes try to call tcgetattr of stdio in
vl.c:This looks reasonable. Except of one thing -- how about renaming
stdio_is_readytostdio_in_use? (I can do that when applying, no need to resend anythnig). Because, well,stdio_is_readyis not obvious at all, at least to me... :)
And oh, the commit comment -- it is not 'terminal crash', it is 'terminal misbehavor' or something like that. Terminal does not crash, it just does not have proper settings after qemu exits.
/mjt
Quoted 9 lines · Michael Tokarev
15.09.2014 16:50, Michael Tokarev пишет:
Quoted 8 lines
Quoted 6 lines · john.liuli
From: Li Liu <[email protected]>
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:
Quoted 8 lines
Quoted 4 lines
This looks reasonable. Except of one thing -- how about renaming
stdio_is_readytostdio_in_use? (I can do that when applying, no need to resend anythnig). Because, well,stdio_is_readyis not obvious at all, at least to me... :)And oh, the commit comment -- it is not 'terminal crash', it is 'terminal misbehavor' or something like that. Terminal does not crash, it just does not have proper settings after qemu exits.
For the record: The 'reset' utility does a full terminal reset and restores sane settings. So usually you can recover from any terminal f*ckup like this by first hitting Ctrl-C [1], then type "reset" [2], then hit Enter.
HTH,
Gerd
[1] To cancel anything which might be at your shell prompt.
[2] Possibly blindly in case echo happens to be turned off.
Markus Armbruster
Reviewed-byQuoted 9 lines · Michael Tokarev
15.09.2014 16:50, Michael Tokarev пишет:
Quoted 8 lines
Quoted 6 lines · john.liuli
From: Li Liu <[email protected]>
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:
Quoted 8 lines
Quoted 4 lines
This looks reasonable. Except of one thing -- how about renaming
stdio_is_readytostdio_in_use? (I can do that when applying, no need to resend anythnig). Because, well,stdio_is_readyis not obvious at all, at least to me... :)And oh, the commit comment -- it is not 'terminal crash', it is 'terminal misbehavor' or something like that. Terminal does not crash, it just does not have proper settings after qemu exits.
Maybe
qemu-char: Permit only a single "stdio" character device
When more than one is used, the terminal settings aren't restored correctly on exit. Fixable. However, such usage makes no sense, because the users race for input, so outlaw it instead.
If you want to connect multiple things to stdio, use the mux chardev.
With the rename proposed by Michael:
Quoted 14 lines · Michael Tokarev
15.09.2014 16:50, Michael Tokarev пишет:
Quoted 6 lines
Quoted 5 lines · john.liuli
From: Li Liu <[email protected]>
Eeay to reproduce, just try "qemu -monitor stdio -nographic" and type "quit", then the terminal will be crashed.
Quoted 6 lines
Quoted 1 line
There are two pathes try to call tcgetattr of stdio in
vl.c:This looks reasonable. Except of one thing -- how about renaming
stdio_is_readytostdio_in_use? (I can do that when applying, no need to resend anythnig). Because, well,stdio_is_readyis not obvious at all, at least to me... :)
Quoted 6 lines
And oh, the commit comment -- it is not 'terminal crash', it is 'terminal misbehavor' or something like that. Terminal does not crash, it just does not have proper settings after qemu exits.
/mjt
Thanks four your comments! Can you help do this when applying incidentally? Or I will resend it again?
Best Regards,
Li.
Quoted 2 lines
.
Quoted 2 lines · Li Liu
Thanks four your comments! Can you help do this when applying incidentally? Or I will resend it again?
http://git.corpit.ru/?p=qemu.git;a=commit;h=6dbc7173f25747b2ed9f3f322ac9697feffe4bf7 -- applied yesteday :)
Thanks,
/mjt