aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorVolker RĂ¼melin <vr_qemu@t-online.de>2021-07-25 18:50:39 +0200
committerGerd Hoffmann <kraxel@redhat.com>2021-07-26 10:24:49 +0200
commit584af1f1d955476aacba3350c4efb5865fc91c09 (patch)
tree95ac7c0950da70581d82791227d5aac0d2ade6ac /ui
parentd4a121048095f276913dca977bb21bcbab02c44c (diff)
downloadqemu-584af1f1d955476aacba3350c4efb5865fc91c09.zip
qemu-584af1f1d955476aacba3350c4efb5865fc91c09.tar.gz
qemu-584af1f1d955476aacba3350c4efb5865fc91c09.tar.bz2
ui/gtk: add a keyboard fifo to the VTE consoles
Since commit 8eb13bbbac ("ui/gtk: vte: fix sending multiple characeters") it's very easy to lock up QEMU with the GTK ui. If you configure a guest with a serial device and the guest doesn't listen on this device, QEMU will lock up after entering two characters in the serial console. That's because current code uses a busy loop for the chardev write retries and the busy loop doesn't terminate in this case. To fix this problem add a fifo to the VTE consoles and use the chr_accept_input() callback function to write the remaining characters in the queue to the chardev. The fifo has a size of 4096 bytes, so one can copy and paste a fairly large URL or file path. Fixes: 8eb13bbbac ("ui/gtk: vte: fix sending multiple characeters") Signed-off-by: Volker RĂ¼melin <vr_qemu@t-online.de> Message-Id: <20210725165039.5242-1-vr_qemu@t-online.de> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/ui/gtk.c b/ui/gtk.c
index 18542c7..974e4df 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1640,6 +1640,25 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
}
}
+static void gd_vc_send_chars(VirtualConsole *vc)
+{
+ uint32_t len, avail;
+
+ len = qemu_chr_be_can_write(vc->vte.chr);
+ avail = fifo8_num_used(&vc->vte.out_fifo);
+ if (len > avail) {
+ len = avail;
+ }
+ while (len > 0) {
+ const uint8_t *buf;
+ uint32_t size;
+
+ buf = fifo8_pop_buf(&vc->vte.out_fifo, len, &size);
+ qemu_chr_be_write(vc->vte.chr, (uint8_t *)buf, size);
+ len -= size;
+ }
+}
+
static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
VCChardev *vcd = VC_CHARDEV(chr);
@@ -1649,6 +1668,14 @@ static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len)
return len;
}
+static void gd_vc_chr_accept_input(Chardev *chr)
+{
+ VCChardev *vcd = VC_CHARDEV(chr);
+ VirtualConsole *vc = vcd->console;
+
+ gd_vc_send_chars(vc);
+}
+
static void gd_vc_chr_set_echo(Chardev *chr, bool echo)
{
VCChardev *vcd = VC_CHARDEV(chr);
@@ -1688,6 +1715,7 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data)
cc->parse = qemu_chr_parse_vc;
cc->open = gd_vc_open;
cc->chr_write = gd_vc_chr_write;
+ cc->chr_accept_input = gd_vc_chr_accept_input;
cc->chr_set_echo = gd_vc_chr_set_echo;
}
@@ -1702,6 +1730,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
gpointer user_data)
{
VirtualConsole *vc = user_data;
+ uint32_t free;
if (vc->vte.echo) {
VteTerminal *term = VTE_TERMINAL(vc->vte.terminal);
@@ -1721,16 +1750,10 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
}
}
- int remaining = size;
- uint8_t* p = (uint8_t *)text;
- while (remaining > 0) {
- int can_write = qemu_chr_be_can_write(vc->vte.chr);
- int written = MIN(remaining, can_write);
- qemu_chr_be_write(vc->vte.chr, p, written);
+ free = fifo8_num_free(&vc->vte.out_fifo);
+ fifo8_push_all(&vc->vte.out_fifo, (uint8_t *)text, MIN(free, size));
+ gd_vc_send_chars(vc);
- remaining -= written;
- p += written;
- }
return TRUE;
}
@@ -1747,6 +1770,7 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,
vc->s = s;
vc->vte.echo = vcd->echo;
vc->vte.chr = chr;
+ fifo8_create(&vc->vte.out_fifo, 4096);
vcd->console = vc;
snprintf(buffer, sizeof(buffer), "vc%d", idx);