From 17331a0c7d0be5409468973e0b838c74eb8bbd25 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 18 Apr 2023 13:02:38 +0100 Subject: [PATCH] frontend: Add FDSTR_INIT macro This initialises fdstr to 'safe' values so we can reliably deinit them. Signed-off-by: Daniel Stone --- compositor/main.c | 2 +- compositor/xwayland.c | 10 +++++----- shared/process-util.c | 3 ++- shared/process-util.h | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/compositor/main.c b/compositor/main.c index 211110135..27be96a3d 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -396,7 +396,7 @@ weston_client_launch(struct weston_compositor *compositor, { struct wl_client *client = NULL; struct custom_env child_env; - struct fdstr wayland_socket; + struct fdstr wayland_socket = FDSTR_INIT; const char *fail_cloexec = "Couldn't unset CLOEXEC on client socket"; const char *fail_seteuid = "Couldn't call seteuid"; char *fail_exec; diff --git a/compositor/xwayland.c b/compositor/xwayland.c index ea1ae1ef5..322a97826 100644 --- a/compositor/xwayland.c +++ b/compositor/xwayland.c @@ -96,11 +96,11 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd { struct wet_xwayland *wxw = user_data; pid_t pid; - struct fdstr wayland_socket; - struct fdstr x11_abstract_socket; - struct fdstr x11_unix_socket; - struct fdstr x11_wm_socket; - struct fdstr display_pipe; + struct fdstr wayland_socket = FDSTR_INIT; + struct fdstr x11_abstract_socket = FDSTR_INIT; + struct fdstr x11_unix_socket = FDSTR_INIT; + struct fdstr x11_wm_socket = FDSTR_INIT; + struct fdstr display_pipe = FDSTR_INIT; char *xserver = NULL; struct weston_config *config = wet_get_config(wxw->compositor); struct weston_config_section *section; diff --git a/shared/process-util.c b/shared/process-util.c index e36c64709..fe895d234 100644 --- a/shared/process-util.c +++ b/shared/process-util.c @@ -68,7 +68,8 @@ fdstr_close_all(struct fdstr *s) unsigned i; for (i = 0; i < ARRAY_LENGTH(s->fds); i++) { - close(s->fds[i]); + if (s->fds[i] >= 0) + close(s->fds[i]); s->fds[i] = -1; } } diff --git a/shared/process-util.h b/shared/process-util.h index 05543f6f6..aa35c7768 100644 --- a/shared/process-util.h +++ b/shared/process-util.h @@ -59,6 +59,7 @@ fdstr_clear_cloexec_fd1(struct fdstr *s); void fdstr_close_all(struct fdstr *s); +#define FDSTR_INIT ((struct fdstr){ { 0 }, { -1, -1 }}) /** * A container for environment variables and/or process arguments, designed to