From e88a62243462c0d5795b8af0cde6722664fba3ed Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Thu, 7 Jul 2022 10:51:56 +0300 Subject: [PATCH] Revert "xwayland: Don't dup() displayfd pipe" This reverts commit 4aa885d4af53817427f9cc552ff5a1da3f5b2f1a. Turns out the problem was not about dupping fds at all, but calling non-async-signal-safe functions like strdup() between fork() and exec() in the child process. For more discussion, see: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/941#note_1457053 Signed-off-by: Pekka Paalanen --- compositor/xwayland.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compositor/xwayland.c b/compositor/xwayland.c index 3de00f62..b5308533 100644 --- a/compositor/xwayland.c +++ b/compositor/xwayland.c @@ -135,6 +135,11 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd return 1; } + if (os_fd_set_cloexec(display_fd[1]) != 0) { + weston_log("failed setting Xwayland end of displayfd as cloexec\n"); + return 1; + } + pid = fork(); switch (pid) { case 0: @@ -149,16 +154,12 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd ret &= dup_fd_to_string(abstract_fd_str, abstract_fd); ret &= dup_fd_to_string(unix_fd_str, unix_fd); ret &= dup_fd_to_string(wm_fd_str, wm[1]); + ret &= dup_fd_to_string(display_fd_str, display_fd[1]); if (!ret) _exit(EXIT_FAILURE); setenv("WAYLAND_SOCKET", wayland_socket_str, 1); - if (snprintf(display_fd_str, sizeof(display_fd_str), "%d", - display_fd[1]) <= 0) { - _exit(EXIT_FAILURE); - } - if (execl(xserver, xserver, display,