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:
committed by
Pekka Paalanen
parent
8aa4571240
commit
9ab97ebd72
+17
-3
@@ -375,21 +375,33 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||||||
weston_process_cleanup_func_t cleanup)
|
weston_process_cleanup_func_t cleanup)
|
||||||
{
|
{
|
||||||
struct wl_client *client = NULL;
|
struct wl_client *client = NULL;
|
||||||
|
struct custom_env child_env;
|
||||||
struct fdstr wayland_socket;
|
struct fdstr wayland_socket;
|
||||||
|
char * const *argp;
|
||||||
|
char * const *envp;
|
||||||
sigset_t allsigs;
|
sigset_t allsigs;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
weston_log("launching '%s'\n", path);
|
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,
|
if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0,
|
||||||
wayland_socket.fds) < 0) {
|
wayland_socket.fds) < 0) {
|
||||||
weston_log("weston_client_launch: "
|
weston_log("weston_client_launch: "
|
||||||
"socketpair failed while launching '%s': %s\n",
|
"socketpair failed while launching '%s': %s\n",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
|
custom_env_fini(&child_env);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fdstr_update_str1(&wayland_socket);
|
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();
|
pid = fork();
|
||||||
switch (pid) {
|
switch (pid) {
|
||||||
@@ -419,11 +431,10 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
setenv("WAYLAND_SOCKET", wayland_socket.str1, 1);
|
if (execve(argp[0], argp, envp)) {
|
||||||
|
|
||||||
if (execl(path, path, NULL) < 0)
|
|
||||||
weston_log("compositor: executing '%s' failed: %s\n",
|
weston_log("compositor: executing '%s' failed: %s\n",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
|
|
||||||
@@ -432,6 +443,7 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||||||
client = wl_client_create(compositor->wl_display,
|
client = wl_client_create(compositor->wl_display,
|
||||||
wayland_socket.fds[0]);
|
wayland_socket.fds[0]);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
|
custom_env_fini(&child_env);
|
||||||
close(wayland_socket.fds[0]);
|
close(wayland_socket.fds[0]);
|
||||||
weston_log("weston_client_launch: "
|
weston_log("weston_client_launch: "
|
||||||
"wl_client_create failed while launching '%s'.\n",
|
"wl_client_create failed while launching '%s'.\n",
|
||||||
@@ -452,6 +464,8 @@ weston_client_launch(struct weston_compositor *compositor,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_env_fini(&child_env);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user