Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
Date: Sat, 28 Mar 2020 18:57:47
Message-Id: 1585421304.28ce410d2aa2eb33d0e61fbf272e1929b734622d.mgorny@gentoo
1 commit: 28ce410d2aa2eb33d0e61fbf272e1929b734622d
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Fri Mar 27 15:14:48 2020 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sat Mar 28 18:48:24 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=28ce410d
7
8 process: Unshare UTS namespace, and set hostname to 'localhost'
9
10 Use UTS namespace to override hostname when network-sandbox is enabled.
11 Set it to 'localhost' as that has a better chance of being present
12 in /etc/hosts. This fixes tests in some packages that try to connect
13 to localhost via hostname obtained using gethostname(), e.g. docker-py,
14 and suffer resolution problems due to the system hostname not being
15 defined in /etc/hosts.
16
17 Closes: https://github.com/gentoo/portage/pull/539
18 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
19
20 lib/portage/process.py | 11 ++++++++++-
21 1 file changed, 10 insertions(+), 1 deletion(-)
22
23 diff --git a/lib/portage/process.py b/lib/portage/process.py
24 index c1fc4bcf6..590116890 100644
25 --- a/lib/portage/process.py
26 +++ b/lib/portage/process.py
27 @@ -348,12 +348,14 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
28 if unshare_net or unshare_ipc or unshare_mount or unshare_pid:
29 # from /usr/include/bits/sched.h
30 CLONE_NEWNS = 0x00020000
31 + CLONE_NEWUTS = 0x04000000
32 CLONE_NEWIPC = 0x08000000
33 CLONE_NEWPID = 0x20000000
34 CLONE_NEWNET = 0x40000000
35
36 if unshare_net:
37 - unshare_flags |= CLONE_NEWNET
38 + # UTS namespace to override hostname
39 + unshare_flags |= CLONE_NEWNET | CLONE_NEWUTS
40 if unshare_ipc:
41 unshare_flags |= CLONE_NEWIPC
42 if unshare_mount:
43 @@ -704,6 +706,13 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
44 noiselevel=-1)
45 os._exit(1)
46 if unshare_net:
47 + # use 'localhost' to avoid hostname resolution problems
48 + try:
49 + socket.sethostname('localhost')
50 + except Exception as e:
51 + writemsg("Unable to set hostname: %s (for FEATURES=\"network-sandbox\")\n" % (
52 + e,),
53 + noiselevel=-1)
54 _configure_loopback_interface()
55 except AttributeError:
56 # unshare() not supported by libc