From b4c4a6acb1204ee53e95744236ee89985db32f91 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 25 Jun 2022 18:14:07 +0100 Subject: guix: inferior: Fix the behaviour of open-inferior #:error-port. I'm looking at this as the Guix Data Service uses this behaviour to record and display logs from inferior processes. * guix/inferior.scm (open-bidirectional-pipe): Call dup2 for file descriptor 2, passing either the file number for the current error port, or a file descriptor for /dev/null. * tests/inferior.scm ("#:error-port stderr", "#:error-port pipe"): Add two new tests that cover some of the #:error-port behaviour. --- guix/inferior.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'guix') diff --git a/guix/inferior.scm b/guix/inferior.scm index 54200b75e4..20a86bbfda 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -156,12 +156,18 @@ custom binary port)." (close-port parent) (close-fdes 0) (close-fdes 1) + (close-fdes 2) (dup2 (fileno child) 0) (dup2 (fileno child) 1) ;; Mimic 'open-pipe*'. - (unless (file-port? (current-error-port)) - (close-fdes 2) - (dup2 (open-fdes "/dev/null" O_WRONLY) 2)) + (if (file-port? (current-error-port)) + (let ((error-port-fileno + (fileno (current-error-port)))) + (unless (eq? error-port-fileno 2) + (dup2 error-port-fileno + 2))) + (dup2 (open-fdes "/dev/null" O_WRONLY) + 2)) (apply execlp command command args)) (lambda () (primitive-_exit 127)))) -- cgit v1.2.3