container: Pass through TERM when calling exec.

* guix/scripts/container/exec.scm (guix-container-exec): Capture the value of
  the TERM environment variable, and pass it through to the container.  This
  means some applications now work where they did not before (e.g. htop), and
  others have more functionality, providing that the terminal was capable of
  enabling that functionality in the first place.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Christopher Baines 2017-01-25 07:24:20 +00:00 committed by Ludovic Courtès
parent e57bd0bed8
commit 0ca575f3bb
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 12 additions and 1 deletions

View File

@ -74,7 +74,14 @@ and the other containing arguments for the command to be executed."
(let* ((opts (parse-command-line args %options '(()) (let* ((opts (parse-command-line args %options '(())
#:argument-handler #:argument-handler
handle-argument)) handle-argument))
(pid (assoc-ref opts 'pid))) (pid (assoc-ref opts 'pid))
(environment (filter-map (lambda (name)
(let ((value (getenv name)))
(and value (cons name value))))
;; Pass through the TERM environment
;; variable to inform processes about
;; the capabilities of the terminal.
'("TERM"))))
(unless pid (unless pid
(leave (_ "no pid specified~%"))) (leave (_ "no pid specified~%")))
@ -89,6 +96,10 @@ and the other containing arguments for the command to be executed."
(lambda () (lambda ()
(match command (match command
((program . program-args) ((program . program-args)
(for-each (match-lambda
((name . value)
(setenv name value)))
environment)
(apply execlp program program program-args))))))) (apply execlp program program program-args)))))))
(unless (zero? result) (unless (zero? result)
(leave (_ "exec failed with status ~d~%") result))))))) (leave (_ "exec failed with status ~d~%") result)))))))