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 <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2022-07-12 17:45:05 +01:00 committed by Pekka Paalanen
parent 8aa4571240
commit 9ab97ebd72
1 changed files with 17 additions and 3 deletions

View File

@ -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;
}