From c43a493ad800b63a53971875bfe53ed3ad773e56 Mon Sep 17 00:00:00 2001 From: LingWindT <49866814+LingWindT@users.noreply.github.com> Date: Tue, 3 Nov 2026 10:00:31 +0900 Subject: [PATCH] preload: set PR_SET_CHILD_SUBREAPER so double-forked Xwayland is not orphaned to init (#1716) --- tools/linuxfs/preload/subreaper.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/linuxfs/preload/subreaper.c diff --git a/tools/linuxfs/preload/subreaper.c b/tools/linuxfs/preload/subreaper.c new file mode 100644 index 000000000..90ed7548d --- /dev/null +++ b/tools/linuxfs/preload/subreaper.c @@ -0,0 +1,24 @@ +/* tools/linuxfs/preload/subreaper.c + * + * Mark every process that loads libblsession.so as a child subreaper. + * + * wlroots starts Xwayland with a double fork: gamescope -> middle process + * (exits immediately) -> Xwayland. With no subreaper in the tree, Xwayland + * is reparented to pid 1 and becomes an orphan. On some vendor kernels + * (observed on Meizu / Flyme 12) an orphan reaper SIGKILLs it in that window, + * which makes gamescope wait forever in wlserver_init() and the UI hangs on + * "Starting display and audio". + * + * With PR_SET_CHILD_SUBREAPER the reparent target becomes the nearest marked + * ancestor instead of init, so the orphan event never happens. + * + * Harmless for processes that do not fork, and cheap (one syscall at load). + */ +#define _GNU_SOURCE +#include + +__attribute__((constructor)) +static void bl_session_set_subreaper(void) +{ + (void)prctl(PR_SET_CHILD_SUBREAPER, 1); +}