poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED 1/2] poked: improve `usock_new' behavior


From: Mohammad-Reza Nabipoor
Subject: [COMMITTED 1/2] poked: improve `usock_new' behavior
Date: Wed, 1 Feb 2023 00:25:05 +0100

2023-01-31  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * poked/usock.c (usock_new): use `pipe2' instead of `pipe'.
        do a F_GETFL before F_SETFL to keep the current flags.
---
 ChangeLog      |  5 +++++
 bootstrap.conf |  1 +
 poked/usock.c  | 14 +++++---------
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c7818a0f..ca4c9fe6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-01-31  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * poked/usock.c (usock_new): use `pipe2' instead of `pipe'.
+       do a F_GETFL before F_SETFL to keep the current flags.
+
 2023-01-31  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * poked/poked.c (poked_options_init): Fix getopt_long to recognize
diff --git a/bootstrap.conf b/bootstrap.conf
index 21295de9..d6a8e71b 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -66,6 +66,7 @@ gnulib_modules="
   readdir
   read-file
   vsnprintf-posix
+  pipe2
   "
 
 # gnulib modules used in libpoke/.
diff --git a/poked/usock.c b/poked/usock.c
index 6edc4e88..aa50a169 100644
--- a/poked/usock.c
+++ b/poked/usock.c
@@ -634,15 +634,10 @@ usock_new (const char *path)
 
   u->pipefd[0] = -1;
   u->pipefd[1] = -1;
-  if (pipe (u->pipefd) == -1)
+  if (pipe2 (u->pipefd, O_CLOEXEC) == -1)
     goto error;
-  if ((flags = fcntl (u->pipefd[0], F_GETFD)) == -1
-      || fcntl (u->pipefd[0], F_SETFD, flags | FD_CLOEXEC) == -1)
-    goto error;
-  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)
+  if ((flags = fcntl (u->pipefd[0], F_GETFL)) == -1
+      || fcntl (u->pipefd[0], F_SETFL, flags | O_NONBLOCK) == -1)
     goto error;
 
   if ((u->fd = socket (AF_UNIX, SOCK_STREAM, 0)) == -1)
@@ -651,7 +646,8 @@ usock_new (const char *path)
   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)
+  if ((flags = fcntl (u->fd, F_GETFL)) == -1
+      || fcntl (u->fd, F_SETFL, flags | O_NONBLOCK) == -1)
     goto error;
 
   memset (&adr, 0, sizeof (adr));
-- 
2.39.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]