From bcd28311f4e2625ae45a21bbcd1817cdcf5ce5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 24 Jul 2021 20:31:14 +0200 Subject: [PATCH] wayland: prevent hang when terminating due to broken Wayland connection If the call to fdm_wayl() with EPOLLHUP was followed by calls to wayl_roundtrip(), foot would hang. The reason for this is that the EPOLLHUP handler in fdm_wayl() would call wl_display_cancel_read(). wayl_roundtrip() also calls wl_display_cancel_read() (since we normally have called wl_display_prepare_read()), before calling wl_display_roundtrip(). When calling wl_display_cancel_read() two times in a row, without a wl_display_prepare_read() in between, wl_display_roundtrip() hangs. Fix by not calling wl_display_cancel_read() in fdm_wayl(). This ensures our invariant holds: wl_display_prepare_read() is *always* in effect outside of fdm_wayl(). Closes #651 --- CHANGELOG.md | 2 ++ wayland.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1857c631..1d325c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ * Crash in scrollback search mode when selection has been canceled due to terminal content updates (https://codeberg.org/dnkl/foot/issues/644). +* Foot process not terminating when the Wayland connection is broken + (https://codeberg.org/dnkl/foot/issues/651). ### Security diff --git a/wayland.c b/wayland.c index a83ef59d..7e9ba629 100644 --- a/wayland.c +++ b/wayland.c @@ -1163,7 +1163,15 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data) if (events & EPOLLHUP) { LOG_WARN("disconnected from Wayland"); - wl_display_cancel_read(wayl->display); + /* + * Do *not* call wl_display_cancel_read() here. + * + * Doing so causes later calls to wayl_roundtrip() (called + * from term_destroy() -> wayl_win_destroy()) to hang + * indefinitely. + * + * https://codeberg.org/dnkl/foot/issues/651 + */ return false; }