Subject: Re: bug#56218: [PATCH] guix: inferior: Fix the behaviour of open-inferior #:error-port.

From: Ludovic Courtès <[email-masked]>
Date: Sun, 26 Jun 2022 17:46:57 +0200

Hi Christopher,

Christopher Baines <[email-masked]> skribis:

> This should be the error port used by the inferior process, but currently it's
> either stderr if #:error-port is a file port, or /dev/null otherwise.

That’s still the case with this patch, no?

The patch does make a difference when (current-error-port) wraps a file
descriptor other than 2 though.

> +++ b/guix/inferior.scm
> @@ -156,12 +156,14 @@ (define (open-bidirectional-pipe command . args)
>              (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))
> +            (dup2 (if (file-port? (current-error-port))
> +                      (fileno (current-error-port))
> +                      (open-fdes "/dev/null" O_WRONLY))
> +                  2)

If (current-error-port) wraps FD 2 when the function is called, then, by
the time we reach (dup2 … 2), the FD behind (current-error-port) has be
closed; we end up doing (dup2 2 2), but FD 2 is closed, so we get EBADF.

Or am I misunderstanding?

Perhaps we should add one test for each case (error port is a file port
vs. error port is another kind of port) in ‘tests/inferior.scm’.

Thanks,
Ludo’.