GNU bug report logs - #52835
[PATCH 0/2] Fix spawning a child not setting standard fds properly

Previous Next

Package: guile;

Reported by: Josselin Poiret <dev <at> jpoiret.xyz>

Date: Mon, 27 Dec 2021 21:27:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Josselin Poiret <dev <at> jpoiret.xyz>
To: Josselin Poiret <dev <at> jpoiret.xyz>, Timothy Sample <samplet <at> ngyro.com>
Cc: 52835 <at> debbugs.gnu.org
Subject: bug#52835: [PATCH v4 2/4] Avoid double closes in piped-process.
Date: Sat, 28 May 2022 14:46:32 +0200
* 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





This bug report was last modified 2 years and 128 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.