summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorJosselin Poiret <dev@jpoiret.xyz>2023-05-05 15:39:23 +0200
committerLudovic Courtès <ludo@gnu.org>2023-05-08 16:06:28 +0200
commit36fd2b4920ae926c79b936c29e739e71a6dff2bc (patch)
treecde55553728dc26e06a004faf1d820ae101f51af /libguile
parentccd7400fdbebca73fc4340ad4ca0248655009f04 (diff)
downloadguile-36fd2b4920ae926c79b936c29e739e71a6dff2bc.tar.gz
Use /dev/null in 'piped-process' if port is not backed by a fdes.HEADmain
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>
Diffstat (limited to 'libguile')
-rw-r--r--libguile/posix.c20
1 files changed, 16 insertions, 4 deletions
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);