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?