Subject: bug#51466: bug#53355: guix shell --check: confusing error message

From: Ludovic Courtès <[email-masked]>
Date: Mon, 14 Feb 2022 10:47:52 +0100

Hi Chris,

Thanks for debugging this!

Chris Marusich <[email-masked]> skribis:

> From c3eea81846ae71a246e6b592be74062f4bf26474 Mon Sep 17 00:00:00 2001
> From: Chris Marusich <[email-masked]>
> Date: Sun, 13 Feb 2022 14:15:14 -0800
> Subject: [PATCH] environment: Prevent PS1 from clobbering output in 'check'.
>
> Fixes: <https://issues.guix.gnu.org/51466>.
>
> * guix/scripts/environment.scm (child-shell-environment): In the script
> executed the child shell, set PS1 to an empty value and then echo three
> sentinel lines to try to "flush" the original PS1 value before printing the
> environment variables.  In the parent process, read and discard all lines up
> to and including the last sentinel line.  After that, read the remaining lines
> as usual.

[...]

> +    ;; Why print "GUIX_FLUSH" a few times?  We are trying to "flush" the
> +    ;; original PS1 value to the port so we can read it (and discard it)
> +    ;; before we start reading the environment variables from the port.  If we
> +    ;; don't do this, the original PS1 value can sometimes get interleaved
> +    ;; into the output, which interferes with our parsing logic.  It's a hack,
> +    ;; but in practice it seems to do the job.  If you know of a more graceful
> +    ;; solution, please implement it!  See: https://issues.guix.gnu.org/51466
> +    "PS1=; for i in 1 2 3; do echo GUIX_FLUSH_$i; done; \
> +env || /usr/bin/env || set; echo GUIX-CHECK-DONE; read x; exit\n")

So you confirm that a single “echo” is not enough, right?

Perhaps we should unroll the ‘for’ loop for portability, to be on the
safe side.  Initially I tested with Bash, Zsh, and Fish:

  https://issues.guix.gnu.org/51285#0-lineno49

I think Fish has a very non-POSIX syntax, hence the suggestion to avoid
‘for’.

I realized that setting PS1 could interfere with the logic below that
checks for PS1.  And since it doesn’t seem to help, perhaps we can
remove “PS1=;”?

Thoughts?

Sorry to answer with yet more questions!

Thanks,
Ludo’.