Re: [gentoo-portage-dev] [PATCH] process: Unshare UTS namespace, and set hostname to 'localhost'

2020-03-27 Thread Zac Medico
On 3/27/20 9:05 AM, Michał Górny wrote:
> Use UTS namespace to override hostname when network-sandbox is enabled.
> Set it to 'localhost' as that has a better chance of being present
> in /etc/hosts.  This fixes tests in some packages that try to connect
> to localhost via hostname obtained using gethostname(), e.g. docker-py,
> and suffer resolution problems due to the system hostname not being
> defined in /etc/hosts.
> ---
>  lib/portage/process.py | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/portage/process.py b/lib/portage/process.py
> index c1fc4bcf6..0f9789acb 100644
> --- a/lib/portage/process.py
> +++ b/lib/portage/process.py
> @@ -348,12 +348,14 @@ def spawn(mycommand, env=None, opt_name=None, 
> fd_pipes=None, returnpid=False,
>   if unshare_net or unshare_ipc or unshare_mount or unshare_pid:
>   # from /usr/include/bits/sched.h
>   CLONE_NEWNS = 0x0002
> + CLONE_NEWUTS = 0x0400
>   CLONE_NEWIPC = 0x0800
>   CLONE_NEWPID = 0x2000
>   CLONE_NEWNET = 0x4000
>  
>   if unshare_net:
> - unshare_flags |= CLONE_NEWNET
> + # UTS namespace to override hostname
> + unshare_flags |= CLONE_NEWNET | CLONE_NEWUTS
>   if unshare_ipc:
>   unshare_flags |= CLONE_NEWIPC
>   if unshare_mount:
> @@ -704,6 +706,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
>   
> noiselevel=-1)
>   os._exit(1)
>   if unshare_net:
> + # use 'localhost' to 
> avoid hostname resolution problems
> + 
> socket.sethostname('localhost')
>   
> _configure_loopback_interface()
>   except AttributeError:
>   # unshare() not supported by libc
> 

Looks good with latest changes in
https://github.com/gentoo/portage/pull/539. Please merge.
-- 
Thanks,
Zac



signature.asc
Description: OpenPGP digital signature


[gentoo-portage-dev] [PATCH] process: Unshare UTS namespace, and set hostname to 'localhost'

2020-03-27 Thread Michał Górny
Use UTS namespace to override hostname when network-sandbox is enabled.
Set it to 'localhost' as that has a better chance of being present
in /etc/hosts.  This fixes tests in some packages that try to connect
to localhost via hostname obtained using gethostname(), e.g. docker-py,
and suffer resolution problems due to the system hostname not being
defined in /etc/hosts.
---
 lib/portage/process.py | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index c1fc4bcf6..0f9789acb 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -348,12 +348,14 @@ def spawn(mycommand, env=None, opt_name=None, 
fd_pipes=None, returnpid=False,
if unshare_net or unshare_ipc or unshare_mount or unshare_pid:
# from /usr/include/bits/sched.h
CLONE_NEWNS = 0x0002
+   CLONE_NEWUTS = 0x0400
CLONE_NEWIPC = 0x0800
CLONE_NEWPID = 0x2000
CLONE_NEWNET = 0x4000
 
if unshare_net:
-   unshare_flags |= CLONE_NEWNET
+   # UTS namespace to override hostname
+   unshare_flags |= CLONE_NEWNET | CLONE_NEWUTS
if unshare_ipc:
unshare_flags |= CLONE_NEWIPC
if unshare_mount:
@@ -704,6 +706,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes,

noiselevel=-1)
os._exit(1)
if unshare_net:
+   # use 'localhost' to 
avoid hostname resolution problems
+   
socket.sethostname('localhost')

_configure_loopback_interface()
except AttributeError:
# unshare() not supported by libc
-- 
2.26.0