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

From: Maxime Devos <[email-masked]>
Date: Sat, 25 Jun 2022 19:50:12 +0200

Christopher Baines schreef op za 25-06-2022 om 18:18 [+0100]:
>              (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)

I don't this would work if (current-error-port) has fd 1. Would
move->fdes be appropriate here?  The following seems less fragile (*)
to me (untested, also I didn't look at the context)

  (move->fdes [child port] 0)
  (move->fdes (dup [child port]) 1)
  (if (file-port? (current-error-port))
      (move->fdes (current-error-port) 2)
      (move->fdes (open-file "/dev/null" O_WRONLY) 2))

(*): move->fdes automatically moves ports out of the way.  Also, if one
of the moves fails, then at least (current-output-port) etc will still
have a correct fd so some error reporting should be possible

Greetings,
Maxime.