Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH] process: Unshare UTS namespace, and set hostname to 'localhost'
Date: Fri, 27 Mar 2020 19:10:26
Message-Id: 694156f4-71f4-9dc2-6f2a-07367c51c19c@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] process: Unshare UTS namespace, and set hostname to 'localhost' by "Michał Górny"
1 On 3/27/20 9:05 AM, Michał Górny wrote:
2 > Use UTS namespace to override hostname when network-sandbox is enabled.
3 > Set it to 'localhost' as that has a better chance of being present
4 > in /etc/hosts. This fixes tests in some packages that try to connect
5 > to localhost via hostname obtained using gethostname(), e.g. docker-py,
6 > and suffer resolution problems due to the system hostname not being
7 > defined in /etc/hosts.
8 > ---
9 > lib/portage/process.py | 6 +++++-
10 > 1 file changed, 5 insertions(+), 1 deletion(-)
11 >
12 > diff --git a/lib/portage/process.py b/lib/portage/process.py
13 > index c1fc4bcf6..0f9789acb 100644
14 > --- a/lib/portage/process.py
15 > +++ b/lib/portage/process.py
16 > @@ -348,12 +348,14 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
17 > if unshare_net or unshare_ipc or unshare_mount or unshare_pid:
18 > # from /usr/include/bits/sched.h
19 > CLONE_NEWNS = 0x00020000
20 > + CLONE_NEWUTS = 0x04000000
21 > CLONE_NEWIPC = 0x08000000
22 > CLONE_NEWPID = 0x20000000
23 > CLONE_NEWNET = 0x40000000
24 >
25 > if unshare_net:
26 > - unshare_flags |= CLONE_NEWNET
27 > + # UTS namespace to override hostname
28 > + unshare_flags |= CLONE_NEWNET | CLONE_NEWUTS
29 > if unshare_ipc:
30 > unshare_flags |= CLONE_NEWIPC
31 > if unshare_mount:
32 > @@ -704,6 +706,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
33 > noiselevel=-1)
34 > os._exit(1)
35 > if unshare_net:
36 > + # use 'localhost' to avoid hostname resolution problems
37 > + socket.sethostname('localhost')
38 > _configure_loopback_interface()
39 > except AttributeError:
40 > # unshare() not supported by libc
41 >
42
43 Looks good with latest changes in
44 https://github.com/gentoo/portage/pull/539. Please merge.
45 --
46 Thanks,
47 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature