All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
@ 2014-09-09 11:19 john.liuli
  2014-09-15 12:50 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 7+ messages in thread
From: john.liuli @ 2014-09-09 11:19 UTC (permalink / raw)
  To: armbru; +Cc: qemu-trivial, Li Liu, peter.huangpeng, kraxel, qemu-devel

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  2014-09-09 11:19 [Qemu-devel] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic" john.liuli
@ 2014-09-15 12:50 ` Michael Tokarev
  2014-09-15 12:57   ` Michael Tokarev
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Tokarev @ 2014-09-15 12:50 UTC (permalink / raw)
  To: john.liuli, armbru; +Cc: qemu-trivial, qemu-devel, peter.huangpeng, kraxel

09.09.2014 15:19, john.liuli wrote:
> 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:

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  2014-09-15 12:50 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2014-09-15 12:57   ` Michael Tokarev
  2014-09-15 13:29     ` Gerd Hoffmann
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Michael Tokarev @ 2014-09-15 12:57 UTC (permalink / raw)
  To: john.liuli, armbru; +Cc: qemu-trivial, kraxel, qemu-devel, peter.huangpeng

15.09.2014 16:50, Michael Tokarev пишет:
> 09.09.2014 15:19, john.liuli wrote:
>> 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:
> 
> 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... :)

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  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
  2 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2014-09-15 13:29 UTC (permalink / raw)
  To: Michael Tokarev
  Cc: qemu-trivial, john.liuli, peter.huangpeng, armbru, qemu-devel

On Mo, 2014-09-15 at 16:57 +0400, Michael Tokarev wrote:
> 15.09.2014 16:50, Michael Tokarev пишет:
> > 09.09.2014 15:19, john.liuli wrote:
> >> 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:
> > 
> > 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... :)
> 
> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  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
  2 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2014-09-15 13:33 UTC (permalink / raw)
  To: Michael Tokarev
  Cc: qemu-trivial, john.liuli, peter.huangpeng, kraxel, qemu-devel

Michael Tokarev <mjt@tls.msk.ru> writes:

> 15.09.2014 16:50, Michael Tokarev пишет:
>> 09.09.2014 15:19, john.liuli wrote:
>>> 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:
>> 
>> 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... :)
>
> 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:

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  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
  2 siblings, 1 reply; 7+ messages in thread
From: Li Liu @ 2014-09-16  1:40 UTC (permalink / raw)
  To: Michael Tokarev, armbru; +Cc: qemu-trivial, kraxel, qemu-devel, peter.huangpeng



On 2014/9/15 20:57, Michael Tokarev wrote:
> 15.09.2014 16:50, Michael Tokarev пишет:
>> 09.09.2014 15:19, john.liuli wrote:
>>> 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:
>>
>> 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... :)
> 
> 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.

> .
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic"
  2014-09-16  1:40     ` Li Liu
@ 2014-09-16  4:20       ` Michael Tokarev
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Tokarev @ 2014-09-16  4:20 UTC (permalink / raw)
  To: Li Liu, armbru; +Cc: qemu-trivial, kraxel, qemu-devel, peter.huangpeng

16.09.2014 05:40, Li Liu wrote:
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-16  4:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-09 11:19 [Qemu-devel] [PATCH v2] qemu-char: fix terminal crash when using "-monitor stdio -nographic" john.liuli
2014-09-15 12:50 ` [Qemu-devel] [Qemu-trivial] " 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.