summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2023-04-18 13:02:38 +0100
committerPekka Paalanen <pq@iki.fi>2023-04-19 08:28:21 +0000
commit17331a0c7d0be5409468973e0b838c74eb8bbd25 (patch)
treeedb73ff08e18c7711ba18af5c1eb773f299f99d5
parent97421545b4313c875f81736f92bad7d7df6a85e6 (diff)
downloadweston-17331a0c7d0be5409468973e0b838c74eb8bbd25.tar.gz
frontend: Add FDSTR_INIT macro
This initialises fdstr to 'safe' values so we can reliably deinit them. Signed-off-by: Daniel Stone <daniels@collabora.com>
-rw-r--r--compositor/main.c2
-rw-r--r--compositor/xwayland.c10
-rw-r--r--shared/process-util.c3
-rw-r--r--shared/process-util.h1
4 files changed, 9 insertions, 7 deletions
diff --git a/compositor/main.c b/compositor/main.c
index 21111013..27be96a3 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 ea1ae1ef..322a9782 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 e36c6470..fe895d23 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 05543f6f..aa35c776 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