From 9ab97ebd72f6e3645f1454ec610a63e523138d29 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 12 Jul 2022 17:45:05 +0100 Subject: [PATCH] wet_process: Use custom_env when forking clients Use the custom_env framework we added for Xwayland when forking to execute clients. This avoids calling the unsafe getenv in between fork and exec. Signed-off-by: Daniel Stone --- compositor/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/compositor/main.c b/compositor/main.c index cf8f6e39..da62684c 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -375,21 +375,33 @@ weston_client_launch(struct weston_compositor *compositor, weston_process_cleanup_func_t cleanup) { struct wl_client *client = NULL; + struct custom_env child_env; struct fdstr wayland_socket; + char * const *argp; + char * const *envp; sigset_t allsigs; pid_t pid; bool ret; weston_log("launching '%s'\n", path); + custom_env_init_from_environ(&child_env); + custom_env_add_arg(&child_env, path); + if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, wayland_socket.fds) < 0) { weston_log("weston_client_launch: " "socketpair failed while launching '%s': %s\n", path, strerror(errno)); + custom_env_fini(&child_env); return NULL; } fdstr_update_str1(&wayland_socket); + custom_env_set_env_var(&child_env, "WAYLAND_SOCKET", + wayland_socket.str1); + + argp = custom_env_get_argp(&child_env); + envp = custom_env_get_envp(&child_env); pid = fork(); switch (pid) { @@ -419,11 +431,10 @@ weston_client_launch(struct weston_compositor *compositor, _exit(EXIT_FAILURE); } - setenv("WAYLAND_SOCKET", wayland_socket.str1, 1); - - if (execl(path, path, NULL) < 0) + if (execve(argp[0], argp, envp)) { weston_log("compositor: executing '%s' failed: %s\n", path, strerror(errno)); + } _exit(EXIT_FAILURE); @@ -432,6 +443,7 @@ weston_client_launch(struct weston_compositor *compositor, client = wl_client_create(compositor->wl_display, wayland_socket.fds[0]); if (!client) { + custom_env_fini(&child_env); close(wayland_socket.fds[0]); weston_log("weston_client_launch: " "wl_client_create failed while launching '%s'.\n", @@ -452,6 +464,8 @@ weston_client_launch(struct weston_compositor *compositor, break; } + custom_env_fini(&child_env); + return client; }