From 8d9ad96b52e5eeeab61a80e09608584172251c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 3 Nov 2019 01:11:02 +0100 Subject: [PATCH 1/2] server: FD_CLOEXEC is a file descriptor flag, not a file status flag --- server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.c b/server.c index 4ca2ada6..a0d6cc94 100644 --- a/server.c +++ b/server.c @@ -291,7 +291,7 @@ server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl) unlink(sock_path); - if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | FD_CLOEXEC) < 0) { + if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0) { LOG_ERRNO("failed to set FD_CLOEXEC on socket"); goto err; } From 8cf981ca12a295b605b2578cd4b347a08a80dee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 3 Nov 2019 01:14:02 +0100 Subject: [PATCH 2/2] slave: turn on FD_CLOEXEC after slave has been spawned This ensures that our ptmx FD isn't carried over to other terminals spawned later. --- slave.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/slave.c b/slave.c index 1f70a0d8..cc41f39a 100644 --- a/slave.c +++ b/slave.c @@ -127,6 +127,15 @@ slave_spawn(int ptmx, int argc, char *const *argv, return -1; } else LOG_DBG("%s: successfully started", conf_shell); + + int fd_flags; + if ((fd_flags = fcntl(ptmx, F_GETFD)) < 0 || + fcntl(ptmx, F_SETFD, fd_flags | FD_CLOEXEC) < 0) + { + LOG_ERRNO("failed to set FD_CLOEXEC on ptmx"); + return -1; + } + break; } }