guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 02/02: Use /dev/null in 'piped-process' if port is not b


From: Ludovic Courtès
Subject: [Guile-commits] 02/02: Use /dev/null in 'piped-process' if port is not backed by a fdes.
Date: Mon, 8 May 2023 10:07:27 -0400 (EDT)

civodul pushed a commit to branch main
in repository guile.

commit 36fd2b4920ae926c79b936c29e739e71a6dff2bc
Author: Josselin Poiret <dev@jpoiret.xyz>
AuthorDate: Fri May 5 15:39:23 2023 +0200

    Use /dev/null in 'piped-process' if port is not backed by a fdes.
    
    In Guile 3.0.9, 'system*' would no longer open /dev/null for file
    descriptors 0, 1, and 2 when its 'current-input-port',
    'current-output-port', or 'current-output-port' is not bound to a file
    port.  This patch reinstates that behavior.
    
    Fixes <https://bugs.gnu.org/63024>.
    
    * 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.
    * test-suite/tests/posix.test ("system*")["https://bugs.gnu.org/63024"]:
    New test.
    * NEWS: Update.
    
    Co-authored-by: Ludovic Courtès <ludo@gnu.org>
---
 NEWS                        |  2 ++
 libguile/posix.c            | 20 ++++++++++++++++----
 test-suite/tests/posix.test | 12 +++++++++++-
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index a63b0aa25..f2e00898f 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,8 @@ the compiler reports it as "possibly unused".
    (<https://bugs.gnu.org/61095>)
 ** Adjust 'spawn' test for GNU/Hurd
    (<https://bugs.gnu.org/62501>)
+** Fix 'system*' with non-file input/output/error port
+   (<https://bugs.gnu.org/63024>)
 ** Hashing of UTF-8 symbols with non-ASCII characters avoids corruption
    (<https://bugs.gnu.org/56413>)
 
diff --git a/libguile/posix.c b/libguile/posix.c
index 6776a7744..4cf4ef383 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1562,10 +1562,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);
diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test
index d5cf47cda..18dad8902 100644
--- a/test-suite/tests/posix.test
+++ b/test-suite/tests/posix.test
@@ -374,7 +374,17 @@
                     (system* "sh" "-c" "echo bong >&2"))))))))
 
       (and (zero? (status:exit-val status))
-           (call-with-input-file file get-string-all)))))
+           (call-with-input-file file get-string-all))))
+
+  (pass-if-equal "https://bugs.gnu.org/63024";
+      0
+    (if (file-exists? "/proc/self/fd/0")          ;on GNU/Linux?
+        (parameterize ((current-output-port (%make-void-port "w0")))
+          (system* "guile" "-c"
+                   (object->string
+                    '(exit (string=? "/dev/null"
+                                     (readlink "/proc/self/fd/1"))))))
+        (throw 'unresolved))))
 
 ;;
 ;; spawn



reply via email to

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