guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/04: environment: Provide /etc/hosts in containers without '--network'


From: guix-commits
Subject: 03/04: environment: Provide /etc/hosts in containers without '--network'.
Date: Fri, 2 Oct 2020 17:29:28 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 0f53c801b91919380a924b402d1ff822bb1dc6ea
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Oct 2 23:17:40 2020 +0200

    environment: Provide /etc/hosts in containers without '--network'.
    
    Fixes <https://bugs.gnu.org/43762>.
    
    * guix/scripts/environment.scm (launch-environment/container): Create
    /etc/hosts when NETWORK? is false.
    * tests/guix-environment-container.sh: Add "localhost" resolution test.
---
 guix/scripts/environment.scm        | 7 +++++++
 tests/guix-environment-container.sh | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index e2e481d..9698111 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -549,6 +549,13 @@ WHILE-LIST."
             (write-passwd (list passwd))
             (write-group groups)
 
+            (unless network?
+              ;; When isolated from the network, provide a minimal /etc/hosts
+              ;; to resolve "localhost".
+              (call-with-output-file "/etc/hosts"
+                (lambda (port)
+                  (display "127.0.0.1 localhost\n" port))))
+
             ;; For convenience, start in the user's current working
             ;; directory or, if unmapped, the home directory.
             (chdir (if map-cwd?
diff --git a/tests/guix-environment-container.sh 
b/tests/guix-environment-container.sh
index 040f32c..3674aa6 100644
--- a/tests/guix-environment-container.sh
+++ b/tests/guix-environment-container.sh
@@ -44,6 +44,10 @@ else
     test $? = 42
 fi
 
+# Make sure "localhost" resolves.
+guix environment --container --ad-hoc --bootstrap guile-bootstrap \
+     -- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))'
+
 # Make sure '--preserve' is honored.
 result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \
    guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]