1 |
Use UTS namespace to override hostname when network-sandbox is enabled. |
2 |
Set it to 'localhost' as that has a better chance of being present |
3 |
in /etc/hosts. This fixes tests in some packages that try to connect |
4 |
to localhost via hostname obtained using gethostname(), e.g. docker-py, |
5 |
and suffer resolution problems due to the system hostname not being |
6 |
defined in /etc/hosts. |
7 |
--- |
8 |
lib/portage/process.py | 6 +++++- |
9 |
1 file changed, 5 insertions(+), 1 deletion(-) |
10 |
|
11 |
diff --git a/lib/portage/process.py b/lib/portage/process.py |
12 |
index c1fc4bcf6..0f9789acb 100644 |
13 |
--- a/lib/portage/process.py |
14 |
+++ b/lib/portage/process.py |
15 |
@@ -348,12 +348,14 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False, |
16 |
if unshare_net or unshare_ipc or unshare_mount or unshare_pid: |
17 |
# from /usr/include/bits/sched.h |
18 |
CLONE_NEWNS = 0x00020000 |
19 |
+ CLONE_NEWUTS = 0x04000000 |
20 |
CLONE_NEWIPC = 0x08000000 |
21 |
CLONE_NEWPID = 0x20000000 |
22 |
CLONE_NEWNET = 0x40000000 |
23 |
|
24 |
if unshare_net: |
25 |
- unshare_flags |= CLONE_NEWNET |
26 |
+ # UTS namespace to override hostname |
27 |
+ unshare_flags |= CLONE_NEWNET | CLONE_NEWUTS |
28 |
if unshare_ipc: |
29 |
unshare_flags |= CLONE_NEWIPC |
30 |
if unshare_mount: |
31 |
@@ -704,6 +706,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, |
32 |
noiselevel=-1) |
33 |
os._exit(1) |
34 |
if unshare_net: |
35 |
+ # use 'localhost' to avoid hostname resolution problems |
36 |
+ socket.sethostname('localhost') |
37 |
_configure_loopback_interface() |
38 |
except AttributeError: |
39 |
# unshare() not supported by libc |
40 |
-- |
41 |
2.26.0 |