VT100 escape responses (DSR) used qemu_chr_be_write() to write directly
to the chardev backend, bypassing the output FIFO, while keyboard input
went through the FIFO and flush path. This inconsistency could lead to
out-of-order delivery when both paths are active.
Introduce qemu_text_console_write() that pushes data into the output
FIFO and flushes it, and use it for both keyboard input and VT100
responses. Remove the now-unnecessary vc_respond_str() helper. Rename
kbd_send_chars() to qemu_text_console_flush() to better reflect its
purpose.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
ui/console-vc.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/ui/console-vc.c b/ui/console-vc.c
index 4ea9f88f55a..8d4178f8cab 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -299,7 +299,7 @@ static void vt100_scroll(QemuVT100 *vt, int ydelta)
vt100_refresh(vt);
}
-static void kbd_send_chars(QemuTextConsole *s)
+static void qemu_text_console_flush(QemuTextConsole *s)
{
uint32_t len, avail;
@@ -316,12 +316,20 @@ static void kbd_send_chars(QemuTextConsole *s)
}
}
+static void qemu_text_console_write(QemuTextConsole *s, const void *buf, size_t len)
+{
+ uint32_t num_free;
+
+ num_free = fifo8_num_free(&s->out_fifo);
+ fifo8_push_all(&s->out_fifo, buf, MIN(num_free, len));
+ qemu_text_console_flush(s);
+}
+
/* called when an ascii key is pressed */
void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
{
uint8_t buf[16], *q;
int c;
- uint32_t num_free;
switch(keysym) {
case QEMU_KEY_CTRL_UP:
@@ -360,9 +368,7 @@ void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
if (s->vt.echo) {
qemu_chr_write(s->chr, buf, q - buf, true);
}
- num_free = fifo8_num_free(&s->out_fifo);
- fifo8_push_all(&s->out_fifo, buf, MIN(num_free, q - buf));
- kbd_send_chars(s);
+ qemu_text_console_write(s, buf, q - buf);
break;
}
}
@@ -673,13 +679,6 @@ static void vc_put_one(VCChardev *vc, int ch)
s->vt.x++;
}
-static void vc_respond_str(VCChardev *vc, const char *buf)
-{
- QemuTextConsole *s = vc->console;
-
- qemu_chr_be_write(s->chr, (const uint8_t *)buf, strlen(buf));
-}
-
/* set cursor, checking bounds */
static void vc_set_cursor(VCChardev *vc, int x, int y)
{
@@ -1018,13 +1017,13 @@ static void vc_putchar(VCChardev *vc, int ch)
switch (vc->esc_params[0]) {
case 5:
/* report console status (always succeed)*/
- vc_respond_str(vc, "\033[0n");
+ qemu_text_console_write(s, "\033[0n", 4);
break;
case 6:
/* report cursor position */
response = g_strdup_printf("\033[%d;%dR",
s->vt.y + 1, s->vt.x + 1);
- vc_respond_str(vc, response);
+ qemu_text_console_write(s, response, strlen(response));
break;
}
break;
@@ -1183,7 +1182,7 @@ static void vc_chr_accept_input(Chardev *chr)
{
VCChardev *drv = VC_CHARDEV(chr);
- kbd_send_chars(drv->console);
+ qemu_text_console_flush(drv->console);
}
static void vc_chr_set_echo(Chardev *chr, bool echo)
--
2.53.0