From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id oMXfN+TQtmLwCgAAbAwnHQ (envelope-from ) for ; Sat, 25 Jun 2022 11:09:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id oBaUN+TQtmKaiQAAauVa8A (envelope-from ) for ; Sat, 25 Jun 2022 11:09:56 +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 700E81B4E5 for ; Sat, 25 Jun 2022 11:09:56 +0200 (CEST) Received: from localhost ([::1]:35540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o51ne-0008SR-4v for larch@yhetil.org; Sat, 25 Jun 2022 05:09:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o51mp-0008Qf-3o for bug-guix@gnu.org; Sat, 25 Jun 2022 05:09:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o51mo-00024S-Rv for bug-guix@gnu.org; Sat, 25 Jun 2022 05:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o51mo-00066J-MF for bug-guix@gnu.org; Sat, 25 Jun 2022 05:09: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: Sat, 25 Jun 2022 09:09: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.165614808523373 (code B ref 53355); Sat, 25 Jun 2022 09:09:02 +0000 Received: (at 53355) by debbugs.gnu.org; 25 Jun 2022 09:08:05 +0000 Received: from localhost ([127.0.0.1]:44096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o51ls-00064q-Vw for submit@debbugs.gnu.org; Sat, 25 Jun 2022 05:08:05 -0400 Received: from mail-pg1-f171.google.com ([209.85.215.171]:44745) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o51lq-00064F-My; Sat, 25 Jun 2022 05:08:03 -0400 Received: by mail-pg1-f171.google.com with SMTP id v126so361167pgv.11; Sat, 25 Jun 2022 02:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Uz3q1/O8m6/I3PE6ziFsunDstEYer1L1ZB4XvD7HmtY=; b=KwRxLKSVEjWeb3I2b5Plq3Pe4Mk05CVBG4MMrQAXeyKyYcmZ+dMaV1py3KOVHMguVu ZKphFpv8O5wiKS9L6KmsBnID3Dpo847XaE+IpM7r7Sfe29lVZzc2DAWf5sEMktFTzJxi ybkM1jkbOA6Y77xr1bROLbZJ1GtgfyJSZsUrhJqTMQCUDUmJnLSNdIiRzkhPEnHoT/JK 1sbi0Sl2vc1HW/sS5z0ry91DfnSYJPCej2E2pGwLzha0uHKLiLl5RrPj4LEeJ8SNZCAK c8zzv5xFsJSE/bUVxADYmKwaZUgizwjFgzB01hwf28eBRnA+DOzRO+b1K/cIdBG+thq3 Bdgg== 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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Uz3q1/O8m6/I3PE6ziFsunDstEYer1L1ZB4XvD7HmtY=; b=rCvPSD6kF/QBpR4BYaj9lTSkMDR+Qi4T+7fFmpeaqVKOy1O2350Hj86jmdRE7qbBsp Y6XG0c8e/3K+6ilIRwp6Mn3+sRnD3UWip6VIBxAJU8vm1LTGDJ+5vb95wUqhZ455YoCv HapU8FEPTPjx5YK7qm6qUunHW6e73uHL5MoB+Qri0PJXdTDHSaBpv28bXv6xwsOrPWNK c9OnJnkO1vNydtC9lixOwBW74Zcz6u6/lylvvD9IumAWsJdOjmrDWNlMzBmOzQcMggEu xbn0WBIiHoOSAOMVgH0nIyS/8x861iKah/Kdh2d5TKdS+QiwQ4UEN3+Vkj1NPqtAn6GX SgSQ== X-Gm-Message-State: AJIora+TIGO97BxhrVUYbN5Ls4QrJd6frudrgsS9V3MlkttVJ2FiBUHr utxVgaO/M4O5/6sacLayfAp4cvMRe4M= X-Google-Smtp-Source: AGRyM1u1xnAanW6Sttnfe/eWfL7izfVlD1SgPZHcvgwOw13nnjDYAPGFcmDlCRekkkZgY8Pp5Bw38Q== X-Received: by 2002:a63:751b:0:b0:40c:9c39:c890 with SMTP id q27-20020a63751b000000b0040c9c39c890mr2859286pgc.302.1656148076321; Sat, 25 Jun 2022 02:07:56 -0700 (PDT) Received: from fedora ([2601:1c0:c800:53d0::aafd]) by smtp.gmail.com with ESMTPSA id a6-20020a056a000c8600b0051c49fb62b7sm3230768pfv.165.2022.06.25.02.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jun 2022 02:07:55 -0700 (PDT) From: Chris Marusich 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> <87sfozzglf.fsf_-_@gmail.com> Date: Sat, 25 Jun 2022 02:07:50 -0700 In-Reply-To: <87sfozzglf.fsf_-_@gmail.com> (Chris Marusich's message of "Mon, 23 May 2022 21:42:36 -0700") Message-ID: <875ykpdsbd.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) 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=1656148196; 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=Uz3q1/O8m6/I3PE6ziFsunDstEYer1L1ZB4XvD7HmtY=; b=i35lu4cYnrbgaL9wjd1l/ymPO3IeVpykw83rpXc3mHNWkyYDp5bZdxg+L1SMByVKzqvPpo DTJIU3KP0EjOb88Br0gUsoqrhJgTrBbRT5jykDh71ws9Gs4rfOZ0DjKbVzyk3NQ2uA8hMH vU7TFXvPRptBnWJ5itf+3hrG0oKgRbxRHmUBrd6zF7jGMoEB8NLcCqc48Hxgsle5sVe8h9 GDwoDN1sg/0qeifkdOk5k6Ddv8KVX7XIw7wuKR4sXeJbrlm7V9L049otKc5jTMpOnmuIPW v7j+PygVvxMpXpVIghsYIbGKUMLXcq7G0qdx/NQ8Bzkj1ecvjbiH4tARxOyolQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656148196; a=rsa-sha256; cv=none; b=PTfFSX19DEwAucmxB66pdupLj58TzayOeF4VyWEZf9XZ0u/YHkGgKHvYO7CtfF1HvjDStF 8CebvIwR/2DUcKZe/mKXcWrG7arPDbtY0eFRfS3Ym7mJ6tOTZ/fULjmrhcMHM/NqLQjWvZ /c44msVcOvI53j53NRl6uEjPxUznV1LlUozVpDVKLrkr0NE9tQOQTNSoQ6jmv//2EVqFXC Kiop3UBV5Eg6UiZtF6u2AU7W+XjlxcQ0dNGY2mBDSVFvNqLiNNIY4oyXh7mUtVlkF1YZtJ ruOpzkFjQbbJGQczUFn1NVdf8npGhEzvGe9lm3DXByE+pb+WrIxcexiMBM3n2g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=KwRxLKSV; 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: 3.13 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=KwRxLKSV; 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: 700E81B4E5 X-Spam-Score: 3.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: yede9B3Kc+Aq --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi Ludo & Everyone, Chris Marusich writes: > Is it OK to rely on shell redirection? It turns out that it is probably not OK to rely on shell redirection in this case, after all. For example, "dash does not support multi-digit file descriptors": https://bugs.launchpad.net/ubuntu/+source/dash/+bug/249620 Indeed, the patch I proposed earlier to rely on shell redirection caused a command like ./pre-inst-env env SHELL=3D/gnu/store/nm0hccsphymxi8c24xmg6ixm9vcf25xb-dash= -0.5.11.5/bin/dash guix shell --check --container -D guix to hang. It hangs because the FD Guile chooses to create and embed in the script is 19 (on my machine, at least). A redirection like "env >&19" causes dash to error out, so no environment information gets sent back to the parent process. The same issue seemed to occur for the ksh from our oksh package. To resolve this, I changed the code so that it just writes to a temporary file. This is simple and more robust. With the attached patch, I was able to use a command like the one above to verify that "guix environment --check" works correctly for Guix-built bash, dash, ksh, fish, zsh, and ash. I also verified that it works for Fedora's /bin/sh and /bin/bash. What do you think of this file-based approach? Supporting many different shells is pretty tricky, but I think this patch does a good enough job. =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 From=20ef8d12a1d44903eafca7153c9344263b1d5d7d56 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) [temporary-file-po= rt] [temporary-file]: New local variables. [script]: Redirect stdout to the temporary file. [lines]: In the parent, send the script to the shell, wait for the shell to exit, and then read lines from the temporary file. Use a dynamic-wind expression to ensure we always close port, close temporary-file-port, and delete temporary-file. =2D-- guix/scripts/environment.scm | 63 ++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 3216235937..b02b0771e3 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,14 +419,27 @@ (define (child-shell-environment shell profile manife= st) (define-values (controller inferior) (openpty)) =20 + (define temporary-file-port (mkstemp "/tmp/guix-env.XXXXXX")) + + (define temporary-file (port-filename temporary-file-port)) + (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 file, there is a risk that the shell= 's + ;; PS1 prompt might clobber the output. See: + ;; https://issues.guix.gnu.org/53355 + (format + #f "env >~a || /usr/bin/env >~a || set >~a; \ +echo GUIX-CHECK-DONE >>~a; exit\n" + temporary-file temporary-file temporary-file temporary-file)) =20 (define lines (match (primitive-fork) + ;; Child (0 (catch #t (lambda () @@ -436,24 +450,33 @@ (define lines (execl shell shell)) (lambda _ (primitive-exit 127)))) + ;; Parent (pid (close-fdes inferior) =2D (let* ((port (fdopen controller "r+l")) =2D (result (begin =2D (display script port) =2D (let loop ((lines '())) =2D (match (read-line port) =2D ((? eof-object?) (reverse lines)) =2D ("GUIX-CHECK-DONE\r" =2D (display "done\n" port) =2D (reverse lines)) =2D (line =2D ;; Drop the '\r' from LINE. =2D (loop (cons (string-drop-right line 1) =2D lines)))))))) =2D (close-port port) =2D (waitpid pid) =2D result)))) + (let* ((port (fdopen controller "r+l"))) + (dynamic-wind + (const #t) + (lambda () + (display script port) + ;; Wait until the shell is done writing to the temporary file. + (waitpid pid) + (let loop ((lines '())) + ;; Read from the temporary file, not from the controller po= rt, to + ;; prevent the shell's PS1 prompt from getting mixed into w= hat we + ;; read. See: https://issues.guix.gnu.org/51466 + (match (read-line temporary-file-port) + ((? eof-object?) (reverse lines)) + ("GUIX-CHECK-DONE" + (reverse lines)) + (line + (loop (cons line lines)))))) + (lambda () + (close-port temporary-file-port) + ;; The temporary file might not exist if something weird happ= ens + ;; in the child shell that prevents it from even writing to t= he + ;; file (e.g. the shell fails to start for some reason). + (false-if-exception (delete-file temporary-file)) + (close-port port))))))) =20 (fold (lambda (line table) ;; Note: 'set' in fish outputs "NAME VALUE" instead of "NAME=3DV= ALUE" base-commit: 319b8331b2357e12ec9edb9665513c32bef56622 =2D-=20 2.34.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJJBAEBCAAzFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAmK20GYVHGNtbWFydXNp Y2hAZ21haWwuY29tAAoJEN1AmhXYIkadIeYQAL0LO5v81twAns5KehxoYWL9R+WS vgWzIixh7PaJygwBd1j8ijY26+ktvRRxUUsU3eYW/YOKdHAFYzVD3RtO4Tmmq5tf +/9rFAJTFqJGvvyjDm1d44/uO3olR/fwVGPHHjjWmpX7XH5vVlNYzToU2VOEwthe 94/EGBpCzzjXWG7vnQOVJaaRcUL0KA/4eWw4RzXPUgulmGSjtFlpgPgRdJE7Q7g2 VxxER6KeNWSoOGw7AtsCYiTi/qa3dYdXxMORgVMjNBSqnM4OB4QKYilxqxCwT+Ds TE3wFkOhTrKtVqoPTmUq6FVPpI7RBZdqI23HrfMloeeOzwRZ4VOvKJRjGzl7VWaB khuibJiwQGQtQtNZKjwwB27NANTCs7F2MnJNd3Lubgr1wlotlxxCfopse3znoIcg KUUmIeclHszqVAS0Cecp69VWO0Pwj1UobRqtB7BZhuNLGjM9nC7uQWL0JD+k1PdL TjGGX34fEZsiofgerul+5m7AWJBg4hQMOqG0m33ha19WFqjhM6nggiFSbyFIJb/Y 6K9IjksS8FBhYK9mAXlRjNbM8HmKREK7KY/71k5YCY+qpQTcP13985XNXVBKLfRG C/lVSRX3pUcZ10QXc8tygVlQ1Ns2F0KM+zvF/xSzWOx0H5oieKszQTSHJdPdt6R7 bMJbCBQ0tsY6PgLE =Cy8Z -----END PGP SIGNATURE----- --==-=-=--