bug#52835: [PATCH v4 2/4] Avoid double closes in piped-process.

Josselin Poiret via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" <[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
* libguile/posix.c (scm_piped_process): Avoid double closes.
---
 libguile/posix.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libguile/posix.c b/libguile/posix.c
index e9f49fa27..155ad09b7 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1475,12 +1475,18 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to)
       if (reading)
         {
           close (c2p[0]);
-          close (c2p[1]);
+          if (c2p[1] != c2p[0])
+            close (c2p[1]);
         }
       if (writing)
         {
-          close (p2c[0]);
-          close (p2c[1]);
+          if (!(reading && (c2p[0] == p2c[0] ||
+                            c2p[1] == p2c[0])))
+            close (p2c[0]);
+          if (p2c[0] != p2c[1] &&
+              !(reading && (c2p[0] == p2c[1] ||
+                            c2p[1] == p2c[1])))
+            close (p2c[1]);
         }
       errno = errno_save;
       SCM_SYSERROR;
@@ -1488,7 +1494,7 @@ scm_piped_process (SCM prog, SCM args, SCM from, SCM to)
 
   if (reading)
     close (c2p[1]);
-  if (writing)
+  if (writing && !(reading && c2p[1] == p2c[0]))
     close (p2c[0]);
 
   return scm_from_int (pid);
-- 
2.36.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.