From 802ef9da8a1c3fa940d76c60f5bf635afa0b16fb Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 9 Jan 2020 13:52:36 +0100 Subject: [PATCH] backend/wayland: handle display errors more gracefully Previously, an error on the remote Wayland display would result in an infinite loop priting: 2020-01-09 13:39:03 - [wayland] Source dispatch function returned negative value! 2020-01-09 13:39:03 - [wayland] This would previously accidentally suppress a follow-up dispatch This happens when the remote compositor disconnects the client because of a protocol error, for instance. Handle wl_display_dispatch and wl_display_dispatch_pending returning -1 by terminating the local display and printing an error. --- backend/wayland/backend.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index c23be048..e5858158 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -34,24 +34,31 @@ static int dispatch_events(int fd, uint32_t mask, void *data) { struct wlr_wl_backend *wl = data; if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { + if (mask & WL_EVENT_ERROR) { + wlr_log(WLR_ERROR, "Failed to read from remote Wayland display"); + } wl_display_terminate(wl->local_display); return 0; } + int count = 0; if (mask & WL_EVENT_READABLE) { - return wl_display_dispatch(wl->remote_display); + count = wl_display_dispatch(wl->remote_display); } if (mask & WL_EVENT_WRITABLE) { wl_display_flush(wl->remote_display); - return 0; } if (mask == 0) { - int count = wl_display_dispatch_pending(wl->remote_display); + count = wl_display_dispatch_pending(wl->remote_display); wl_display_flush(wl->remote_display); - return count; } - return 0; + if (count < 0) { + wlr_log(WLR_ERROR, "Failed to dispatch remote Wayland display"); + wl_display_terminate(wl->local_display); + return 0; + } + return count; } static void xdg_wm_base_handle_ping(void *data,