From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KAVWMTZzYl9vJQAA0tVLHw (envelope-from ) for ; Wed, 16 Sep 2020 20:19:02 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id iHRELTZzYl9bDAAA1q6Kng (envelope-from ) for ; Wed, 16 Sep 2020 20:19:02 +0000 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 2A9099404CF for ; Wed, 16 Sep 2020 20:19:02 +0000 (UTC) Received: from localhost ([::1]:33998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIdtN-0002HC-17 for larch@yhetil.org; Wed, 16 Sep 2020 16:19:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIdrm-0001O3-Ct for guix-devel@gnu.org; Wed, 16 Sep 2020 16:17:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:48502) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIdrk-0007xk-Of; Wed, 16 Sep 2020 16:17:20 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=40096 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kIdrk-0005kD-5f; Wed, 16 Sep 2020 16:17:20 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Danny O'Brien Subject: Re: =?utf-8?Q?=E2=80=98guix_environment=E2=80=99?= vs. =?utf-8?Q?=E2=80=98=2Ebash=5Fprofile=E2=80=99?= References: <874ko14bjt.fsf@spesh.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Jour de la Vertu de =?utf-8?Q?l'Ann=C3=A9e?= 228 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Wed, 16 Sep 2020 22:17:06 +0200 In-Reply-To: <874ko14bjt.fsf@spesh.com> (Danny O'Brien's message of "Sun, 13 Sep 2020 14:22:14 -0700") Message-ID: <87v9gdlbnh.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org, Brendan Tildesley Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Spam-Score: -1.01 X-TUID: wmLTAySfCEXC --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hey, I was toying with the idea of automatically detecting discrepancies in environment variables, so I tried the attached patch, which would check /proc/PID/environ compared to the profile=E2=80=99s search path variables. Unfortunately, that doesn=E2=80=99t work because Bash for instance does not change its own environment variables (with setenv(3) or environ(7)) when you type =E2=80=9Cexport PATH=3Dfoo=E2=80=9D or similar (which makes sense,= after all). I=E2=80=99m thinking the only solution left would be to grep ~/.bashrc and similar for potentially problematic environment variable settings. Should we do that every time? Or=E2=80=A6? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index ad50281eb2..33d5bd736a 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -43,7 +43,9 @@ #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:use-module (ice-9 textual-ports) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) @@ -424,6 +426,50 @@ regexps in WHITE-LIST." ((program . args) (apply execlp program program args)))) +(define-immutable-record-type + (environment-discrepancy path expected actual) + environment-discrepancy? + (path environment-discrepancy-path) + (expected environment-discrepancy-expected) + (actual environment-discrepancy-actual)) + +(define (process-environment-variables pid) + (define split-on-nul + (cute string-tokenize <> + (char-set-complement (char-set #\nul)))) + + (define (split-on-= str) + (let ((offset (string-index str #\=))) + (cons (string-take str offset) + (string-drop str (+ 1 offset))))) + + (call-with-input-file (string-append "/proc/" (number->string pid) + "/environ") + (lambda (port) + (map split-on-= + (split-on-nul (get-string-all port)))))) + +(define (process-environment-discrepancies pid profile manifest) + (let ((variables (process-environment-variables pid)) + (paths (profile-search-paths profile manifest))) + (filter-map (match-lambda + ((path . value) + (let ((name (search-path-specification-variable + path))) + (match (assoc-ref variables name) + (#f + (environment-discrepancy path value #f)) + (actual + (pk 'var name actual value) + (and (not (string-prefix? value + actual)) + (environment-discrepancy path + value actual))))))) + paths))) + +(define (check-environment pid profile manifest) + (pk 'disc (process-environment-discrepancies pid profile manifest))) + (define* (launch-environment/fork command profile manifest #:key pure? (white-list '())) "Run COMMAND in a new process with an environment containing PROFILE, with @@ -434,8 +480,11 @@ regexps in WHITE-LIST." (0 (launch-environment command profile manifest #:pure? pure? #:white-list white-list)) - (pid (match (waitpid pid) - ((_ . status) status))))) + (pid + (sleep 1) + (check-environment pid profile manifest) + (match (waitpid pid) + ((_ . status) status))))) (define* (launch-environment/container #:key command bash user user-mappings profile manifest link-profile? network? --=-=-=--