From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kEDBDn9ijGIRJgEAbAwnHQ (envelope-from ) for ; Tue, 24 May 2022 06:43:43 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 6Pa8Dn9ijGKaagEA9RJhRA (envelope-from ) for ; Tue, 24 May 2022 06:43:43 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CFA0B47DDD for ; Tue, 24 May 2022 06:43:41 +0200 (CEST) Received: from localhost ([::1]:55598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntMOS-0003zg-Vb for larch@yhetil.org; Tue, 24 May 2022 00:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntMNr-0003y5-Ac for bug-guix@gnu.org; Tue, 24 May 2022 00:43:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ntMNr-0002L3-1G for bug-guix@gnu.org; Tue, 24 May 2022 00:43:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ntMNq-0006gK-Vk for bug-guix@gnu.org; Tue, 24 May 2022 00:43:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#53355: guix shell --check: confusing error message Resent-From: Chris Marusich Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 24 May 2022 04:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53355 X-GNU-PR-Package: guix X-GNU-PR-Keywords: moreinfo To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 53355@debbugs.gnu.org, 51466@debbugs.gnu.org Received: via spool by 53355-submit@debbugs.gnu.org id=B53355.165336737325659 (code B ref 53355); Tue, 24 May 2022 04:43:02 +0000 Received: (at 53355) by debbugs.gnu.org; 24 May 2022 04:42:53 +0000 Received: from localhost ([127.0.0.1]:50678 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ntMNf-0006fl-0x for submit@debbugs.gnu.org; Tue, 24 May 2022 00:42:53 -0400 Received: from mail-pj1-f53.google.com ([209.85.216.53]:42585) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ntMNZ-0006fJ-Ju; Tue, 24 May 2022 00:42:46 -0400 Received: by mail-pj1-f53.google.com with SMTP id cs3-20020a17090af50300b001e0808b5838so172190pjb.1; Mon, 23 May 2022 21:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=FyVdNXjH+IFW6AjTnaVP7nuT0I3g6b4rFTMUIs0Feuk=; b=hVZ4uRfOKxSq+pxv4ZcniSZkl+WQ1maybsJZCks1nHR0lAmAiBSga8IGPocFHdmFpQ xtPLSOnm9guBXBS1mVsL6ta851GtKx1jSIf1fLTp/l8QWymWfCJvUH2YcYxUBunkkexm elwoCeHTsQzDGfBWfukCIvx+ViB43L/ZC0IHatEMxpuLF1OK1qqQT/X1lJOdGBrpMVXQ A2tAcestFUh+rAh3ZIDTtoZQxJgITezG9Uj6SC9TFF7jkZQqUkkq1HAEMEb7L9aSLfGR 2+EEW9jwsRED8mU5OwXQT30sTj3SOdETC0gHHKMnbub19fDL7qRbHJRGStGor4ldXtwI 0XdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version; bh=FyVdNXjH+IFW6AjTnaVP7nuT0I3g6b4rFTMUIs0Feuk=; b=KJ22pzKS/SWqR7qh4g6lF36Wz3XzF+p3BgWUzQqRpq6y8uEzDKFWR6kVPzaTbVxUhB zmhH67x0Mqf70ZKGd9zuGzyFvV83PbnqL+OSlpMK4OKkVAumIpkjCXAs5FvCaJRgleZH mL3N1gJmkXr4XU4K5TQsK0CM+20VPiCga4USKjZiaPNywSOSon+avPcCYQjWRmYABbKC hk7hxUjIxAzEa7NdbHp4PsyWq7rdfrPL/NrfnAvixRD1oYzYPLzSnQ3qNbwrOqCmQBBX PZGXYCfMievdb8FIF5pZlbplk+s2c9qJGg1mfU8de9/fJ1/ZjCqXkD/OCfJ/sNoDVQsE NH9w== X-Gm-Message-State: AOAM530WnKDLoAvYetBJm32SVrB4xsNxEGRvo7PhuxzGX9qOSxwJAvLo kOdlWSvVWsUCRYtEmhbai0jZzBiAfbUaoQ== X-Google-Smtp-Source: ABdhPJyHEagP8xig8EhTL6lJULtEfwKNZURes9zgyZiveRJu9BI7FY+hOdCvikGtqd4tepTEOWw3SQ== X-Received: by 2002:a17:902:eb8d:b0:161:db34:61f8 with SMTP id q13-20020a170902eb8d00b00161db3461f8mr24040576plg.91.1653367359190; Mon, 23 May 2022 21:42:39 -0700 (PDT) Received: from fedora ([2601:601:9d82:820::e44b]) by smtp.gmail.com with ESMTPSA id w10-20020a62c70a000000b0050dc7628180sm8400140pfg.90.2022.05.23.21.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 21:42:37 -0700 (PDT) From: Chris Marusich In-Reply-To: <878rudzsmv.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Mon, 14 Feb 2022 10:47:52 +0100") References: <87h7a08kub.fsf@gmail.com> <87lez5td4n.fsf@gnu.org> <87sftc4osu.fsf@gmail.com> <87h79slysd.fsf@gnu.org> <87sft13dyv.fsf@gmail.com> <874k59d802.fsf@gnu.org> <87wnhy2w73.fsf_-_@gmail.com> <878rudzsmv.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Date: Mon, 23 May 2022 21:42:36 -0700 Message-ID: <87sfozzglf.fsf_-_@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653367421; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=FyVdNXjH+IFW6AjTnaVP7nuT0I3g6b4rFTMUIs0Feuk=; b=kMja2XMFn3P0xrN7QHnkYsf5ZABS6zYXXLxmR74IXDURgU3iIJAC73A5zjO/WDApl9FlAd JWXU4xLfyJ3ksv45T13uM2Zbd8pqvh59CvM0k9/yeDL9zzNo5WFiKsc/EsCRE4QEJ6K5tH +sr9c8nhUY4C964fsAB2YqaTNeEYMCREJGuUFSx/LCsb66qhW9PceN1pFrm1RY5snpHbLt vLUOvLAuHW/WchBmy4wc4jvjsZWAciCznFzoxkiRiQRE0KjZc5t7f3Xiib70g/W2omRUvW jmH9rMhaUW9Fb8p8pyB6p70RV5fY9mGO4mk4wmUH+3PCmzkgmPfVBZHZcCtHGg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653367421; a=rsa-sha256; cv=none; b=WVWEwityNtaqjxpaAgqn85YEs2v0zdbkv0jdiOTx2OqHaKmoHQqXGymDClt0SPs4J2tb5O BeJWZq08RW68oGf+qcGCFjFKkxLebRsnbibTW9THmkfSw3HlibGcgwqJO7awWrJoTSOAxw 0EwcSqTubhr2GWbeAOEeKT3hLYA7FRLdZGXRNqXzBH8db/DUGc3JjHW6hoJYXUTo3Bt1Ig ESFaLnFcgiw4ux1VJf5oRH6k6RnxnbCOGWfE06857SD710s6MTAVrkXbpux0sSya85Vofk h2Q22J+6irKnjHw0PS/vigOlN46vMWVyjXvsuyGCbIWtST72JcSj0SJOkIrzVQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=hVZ4uRfO; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 5.35 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=hVZ4uRfO; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: CFA0B47DDD X-Spam-Score: 5.35 X-Migadu-Scanner: scn1.migadu.com X-TUID: FXUWng2eNSb9 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ludo, Ludovic Court=C3=A8s writes: > So you confirm that a single =E2=80=9Cecho=E2=80=9D is not enough, right? I didn't test one specifically. It might work with just one, but it did work with three. If we want to proceed with the "echo" approach, let me know and I'll test just one echo to see if that is reliable enough. > Perhaps we should unroll the =E2=80=98for=E2=80=99 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 > =E2=80=98for=E2=80=99. I see. Yes, I'll do that if we decide to go with the echo-based approach. > I realized that setting PS1 could interfere with the logic below that > checks for PS1. And since it doesn=E2=80=99t seem to help, perhaps we can > remove =E2=80=9CPS1=3D;=E2=80=9D? I recall that I tried removing PS1, and I still had trouble. I believe it was because even if we unset PS1 as the very first command we do, the original prompt is still printed. Foreign distros usually set PS1 to something, and whatever that is will be printed before we have a chance to input any commands. It's hard to avoid that in general. > Thoughts? One alternative method I tried successfully in a variety of shells was to use shell redirection (see attached). I like this approach. However, this will only work in shells that support redirection. I recall testing with bash, ash (busybox's shell), dash, zsh, fish, ksh, and csh. I recall that only csh failed, since it doesn't support redirection. I personally like the attached patch better than what I proposed earlier. The earlier patch just echoes a few times. Presumably, it only works because the PS1 prompt is likely (but not guaranteed) to be emitted before the last of the echo commands finishes printing. I'd rather just control the desired output and ignore PS1 entirely, and that is what the attached patch accomplishes using FDs. However, if support for shells without redirection is a requirement, then maybe the original hack (echo a few times) is OK, or perhaps we need something else. How would you like to proceed? Is it OK to rely on shell redirection? =2D-=20 Chris PGP: https://savannah.gnu.org/people/viewgpg.php?user_id=3D106836 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-environment-Prevent-PS1-from-clobbering-output-in-ch.patch Content-Transfer-Encoding: quoted-printable Content-Description: [PATCH] environment: Prevent PS1 from clobbering output in 'check'. From=209a1cef589abf01b61e22656f44c76441f4c50ffd Mon Sep 17 00:00:00 2001 From: Chris Marusich Date: Fri, 11 Mar 2022 00:20:12 -0800 Subject: [PATCH] environment: Prevent PS1 from clobbering output in 'check'. Fixes: . * guix/scripts/environment.scm (child-shell-environment) [shell-pipe] [shell-pipe-in, shell-pipe-out]: New local variables. [script]: Redirect the stdout of each command to the file descriptor of the shell-pipe-out port. [lines]: In the child, close shell-pipe-in before starting the shell. In t= he parent, close shell-pipe-out before sending the script to the shell. Read lines from shell-pipe-in, not port, so that the shell's PS1 prompt cannot clobber the lines. Close shell-pipe-in just before waiting on the child. =2D-- guix/scripts/environment.scm | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 3216235937..f0cb341aab 100644 =2D-- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -48,6 +48,7 @@ (define-module (guix scripts environment) #:autoload (gnu packages bash) (bash) #:autoload (gnu packages bootstrap) (bootstrap-executable %bootstrap-g= uile) #:use-module (ice-9 match) + #:use-module (ice-9 format) #:autoload (ice-9 rdelim) (read-line) #:use-module (ice-9 vlist) #:use-module (srfi srfi-1) @@ -418,11 +419,23 @@ (define (child-shell-environment shell profile manife= st) (define-values (controller inferior) (openpty)) =20 + (define shell-pipe (pipe)) + (define shell-pipe-in (car shell-pipe)) + (define shell-pipe-out (cdr shell-pipe)) + (define script =2D ;; Script to obtain the list of environment variable values. On a P= OSIX =2D ;; shell we can rely on 'set', but on fish we have to use 'env' (fis= h's =2D ;; 'set' truncates values and prints them in a different format.) =2D "env || /usr/bin/env || set; echo GUIX-CHECK-DONE; read x; exit\n") + ;; Script to obtain the list of environment variable values. + ;; + ;; On a POSIX shell we can rely on 'set', but on fish we have to use '= env' + ;; (fish's 'set' truncates values and prints them in a different forma= t). + ;; + ;; Unless we redirect output to a dedicated file descriptor, there is a + ;; risk that the shell's PS1 prompt might clobber the output. See: + ;; https://issues.guix.gnu.org/53355 + (let ((out-fd (port->fdes shell-pipe-out))) + (format + #f "env 1>&~d || /usr/bin/env 1>&~d || set 1>&~d; \ +echo GUIX-CHECK-DONE 1>&~d; read x; exit\n" out-fd out-fd out-fd out-fd))) =20 (define lines (match (primitive-fork) @@ -432,17 +445,22 @@ (define lines (load-profile profile manifest #:pure? #t) (setenv "GUIX_ENVIRONMENT" profile) (close-fdes controller) + (close-port shell-pipe-in) (login-tty inferior) (execl shell shell)) (lambda _ (primitive-exit 127)))) (pid (close-fdes inferior) + (close-port shell-pipe-out) (let* ((port (fdopen controller "r+l")) (result (begin (display script port) (let loop ((lines '())) =2D (match (read-line port) + ;; Read from our special port, not from the + ;; controller port, to prevent the shell's PS1 + ;; prompt from getting mixed into what we read. + (match (read-line shell-pipe-in) ((? eof-object?) (reverse lines)) ("GUIX-CHECK-DONE\r" (display "done\n" port) @@ -452,6 +470,7 @@ (define lines (loop (cons (string-drop-right line 1) lines)))))))) (close-port port) + (close-port shell-pipe-in) (waitpid pid) result)))) =20 base-commit: adf5ae5a412ed13302186dd4ce8e2df783d4515d =2D-=20 2.34.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJJBAEBCAAzFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAmKMYjwVHGNtbWFydXNp Y2hAZ21haWwuY29tAAoJEN1AmhXYIkadGUoQAJXWVsqVTXddDRXcOeqM0f0YX3/Y 3JXnXJF+H+uGDU/X7ol+5f/Alq1gH9zbSP4SExwPYHPt5v/kg3RPQB2sWlg7xmrX pHlh00XhLbZASgAXFtbIzNRAxDtcTKkE5U2dBHj9fFmY30PMfd8nItkkFW2JxYsf 61bHUO9J3kx4z5Ud6MEntqBqa9l1tw4UCmOAW8s7MNQvcyL2N5DIFLnSvG0wiSTZ jvoPoUX5MGX/ByRGvRtsWObIp9790gmS9ERd/aBYsw7n82bgSTTkj+S9ryJUmFGA lOodZ1l6ydYisKvDutVhuCNsIzsu88NC9pf3vEnweLtg/Se7V9oRat+e1lOfYImU kVRKVKkk1XGeePCR1U2FMH3YypiGx3gCoULjBI6Sxk+Eo+MbAHTZKZnHBC1Bxx0j fGoxM5QYoDZJaIll2uwoWUyJjCVifETFSXETxZeXGrrXPQmqQnd5CRaK7cB//9TC MWH933SZDanOkUe/bfIjt/I+FtwBJQatlIEJJuskh5B1UqFQ1EN6olG69PAb84IA BcWKZ14sd/5KChhfdRhCOhW6qFAQe2pfijpRV3kD9dMIWRV2InSbiHymlKfX+W3V KnH1bKQdT9FPEz0KQCX68HXYa06F0a4Fm5oomZD6h4UJH/csbn7EIDlDxBbzLwia 59Y6quGxi8sRtL7v =1Fcq -----END PGP SIGNATURE----- --==-=-=--