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); +}