From 3fdc76f128a571b181417a07d78aedd7dbbbb72c Mon Sep 17 00:00:00 2001 From: David Arroyo Date: Sat, 1 Feb 2025 21:52:41 +0100 Subject: [PATCH] Fix unexpected devdraw crashes on sway I found sway 1.10 and wlroots 0.18.2 will occasionally generate wl_keyboard::keymap events with an empty keymap. I do not have a reliable reproduction for this, but it seems to occur when switching back and forth between workspaces with the keyboard. This also fixes the issue where devdraw can go into a busy loop if the compositor goes away and wl_display_dispatch() returns -1. --- src/cmd/devdraw/wayland.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/devdraw/wayland.c b/src/cmd/devdraw/wayland.c index 5391d77e..9683ff77 100644 --- a/src/cmd/devdraw/wayland.c +++ b/src/cmd/devdraw/wayland.c @@ -616,8 +616,13 @@ static const struct wl_pointer_listener pointer_listener = { void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size) { - DEBUG("wl_keyboard_keymap\n"); + DEBUG("wl_keyboard_keymap(format=%d, fd=%d, size=%d)\n", format, fd, size); char *keymap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + if (keymap == MAP_FAILED) { + DEBUG("wl_keyboard_keymap: %s", strerror(errno)); + return; + } + Client* c = data; WaylandClient *wl = (WaylandClient*) c->view; qlock(&wayland_lock); @@ -852,8 +857,9 @@ void gfx_main(void) { entered_gfx_loop = 1; gfx_started(); DEBUG("gfx_main: entering loop\n"); - while (wl_display_dispatch(wl_display)) + while (wl_display_dispatch(wl_display) > 0 || errno == EAGAIN) ; + sysfatal("wl_display_dispatch: %r"); } static void rpc_resizeimg(Client*) {