From 71b40fc76b4c87969a9c0949409f83130567a890 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Thu, 7 Jul 2022 11:15:42 +0300 Subject: [PATCH] xwayland: move config reading up Doing any kind of memory allocation calls between fork() and exec() in the child process is prone to deadlocks and explosions. In general, only async-signal-safe functions are safe there. Move the config access to the parent process before fork() to avoid problems. See also: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/941#note_1457053 Signed-off-by: Pekka Paalanen --- compositor/xwayland.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compositor/xwayland.c b/compositor/xwayland.c index b5308533..28092681 100644 --- a/compositor/xwayland.c +++ b/compositor/xwayland.c @@ -140,13 +140,13 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd return 1; } + section = weston_config_get_section(config, "xwayland", NULL, NULL); + weston_config_section_get_string(section, "path", + &xserver, XSERVER_PATH); + pid = fork(); switch (pid) { case 0: - section = weston_config_get_section(config, - "xwayland", NULL, NULL); - weston_config_section_get_string(section, "path", - &xserver, XSERVER_PATH); /* SOCK_CLOEXEC closes both ends, so we need to unset * the flag on the client fd. */ @@ -205,6 +205,8 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd break; } + free(xserver); + return pid; }