[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED 2/2] poked: enable FD_CLOEXEC flag the right way
From: |
Mohammad-Reza Nabipoor |
Subject: |
[COMMITTED 2/2] poked: enable FD_CLOEXEC flag the right way |
Date: |
Tue, 24 Jan 2023 09:22:40 +0100 |
Reported by Eric Blake.
2023-01-24 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* poked/usock.c (usock_new): Don't blindly set FD_CLOEXEC; first
get the flags, enable the FD_CLOEXEC flag and set new the flag.
---
ChangeLog | 5 +++++
poked/usock.c | 10 +++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0fd5b4ec..107f7cb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-01-24 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * poked/usock.c (usock_new): Don't blindly set FD_CLOEXEC; first
+ get the flags, enable the FD_CLOEXEC flag and set new the flag.
+
2023-01-24 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pkl-rt.pk (get_time): Renamed to `gettime'.
diff --git a/poked/usock.c b/poked/usock.c
index 28559b59..6edc4e88 100644
--- a/poked/usock.c
+++ b/poked/usock.c
@@ -621,6 +621,7 @@ usock_new (const char *path)
{
struct usock *u;
struct sockaddr_un adr;
+ int flags;
u = calloc (1, sizeof (*u));
if (u == NULL)
@@ -635,9 +636,11 @@ usock_new (const char *path)
u->pipefd[1] = -1;
if (pipe (u->pipefd) == -1)
goto error;
- if (fcntl (u->pipefd[0], F_SETFD, FD_CLOEXEC) == -1)
+ if ((flags = fcntl (u->pipefd[0], F_GETFD)) == -1
+ || fcntl (u->pipefd[0], F_SETFD, flags | FD_CLOEXEC) == -1)
goto error;
- if (fcntl (u->pipefd[1], F_SETFD, FD_CLOEXEC) == -1)
+ if ((flags = fcntl (u->pipefd[1], F_GETFD)) == -1
+ || fcntl (u->pipefd[1], F_SETFD, flags | FD_CLOEXEC) == -1)
goto error;
if (fcntl (u->pipefd[0], F_SETFL, O_NONBLOCK) == -1)
goto error;
@@ -645,7 +648,8 @@ usock_new (const char *path)
if ((u->fd = socket (AF_UNIX, SOCK_STREAM, 0)) == -1)
goto error;
- if (fcntl (u->fd, F_SETFD, FD_CLOEXEC) == -1)
+ if ((flags = fcntl (u->fd, F_GETFD)) == -1
+ || fcntl (u->fd, F_SETFD, flags | FD_CLOEXEC) == -1)
goto error;
if (fcntl (u->fd, F_SETFL, O_NONBLOCK) == -1)
goto error;
--
2.39.1