GNU bug report logs - #62334
Guile's "sleep pipe" can leak into processes created by 'spawn'

Previous Next

Package: guix;

Reported by: Greg Hogan <code <at> greghogan.com>

Date: Tue, 21 Mar 2023 14:18:02 UTC

Severity: important

Merged with 62765, 63024

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

Bug is archived. No further changes may be made.

Full log


Message #55 received at 62334 <at> debbugs.gnu.org (full text, mbox):

From: Josselin Poiret <dev <at> jpoiret.xyz>
To: Ludovic Courtès <ludo <at> gnu.org>,
 Josselin Poiret <dev <at> jpoiret.xyz>
Cc: 63024 <at> debbugs.gnu.org, 62334 <at> debbugs.gnu.org,
 Greg Hogan <code <at> greghogan.com>, Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: [PATCH 2/3] Use /dev/null in piped-process if port is not backed by a
 fdes
Date: Fri,  5 May 2023 15:39:23 +0200
From: Josselin Poiret <dev <at> jpoiret.xyz>

* libguile/posix.c (piped_process): Open /dev/null to use as in/out/err
if the corresponding port is not backed by a file descriptor.
---
 libguile/posix.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libguile/posix.c b/libguile/posix.c
index 2969f1f24..f41a99efe 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1558,10 +1558,22 @@ piped_process (pid_t *pid, SCM prog, SCM args, SCM from, SCM to)
 
     if (SCM_OPOUTFPORTP ((port = scm_current_error_port ())))
       err = SCM_FPORT_FDES (port);
-    if (out == -1 && SCM_OPOUTFPORTP ((port = scm_current_output_port ())))
-      out = SCM_FPORT_FDES (port);
-    if (in == -1 && SCM_OPINFPORTP ((port = scm_current_input_port ())))
-      in = SCM_FPORT_FDES (port);
+    else
+      err = open ("/dev/null", O_WRONLY | O_CLOEXEC);
+    if (out == -1)
+      {
+        if (SCM_OPOUTFPORTP ((port = scm_current_output_port ())))
+          out = SCM_FPORT_FDES (port);
+        else
+          out = open ("/dev/null", O_WRONLY | O_CLOEXEC);
+      }
+    if (in == -1)
+      {
+        if (SCM_OPINFPORTP ((port = scm_current_input_port ())))
+          in = SCM_FPORT_FDES (port);
+        else
+          in = open ("/dev/null", O_RDONLY | O_CLOEXEC);
+      }
   }
 
   *pid = do_spawn (exec_file, exec_argv, exec_env, in, out, err, 1);
-- 
2.39.2





This bug report was last modified 255 days ago.

Previous Next


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