From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 861C4138350 for ; Sat, 28 Mar 2020 18:57:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BF8C3E0AB7; Sat, 28 Mar 2020 18:57:46 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A4210E0AB7 for ; Sat, 28 Mar 2020 18:57:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 726C134FA7A for ; Sat, 28 Mar 2020 18:57:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D84B8162 for ; Sat, 28 Mar 2020 18:57:43 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1585421304.28ce410d2aa2eb33d0e61fbf272e1929b734622d.mgorny@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/process.py X-VCS-Directories: lib/portage/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 28ce410d2aa2eb33d0e61fbf272e1929b734622d X-VCS-Branch: master Date: Sat, 28 Mar 2020 18:57:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 628d955b-1329-449d-a248-ff3fc799451d X-Archives-Hash: 35c8b4c868f55167adc0dd3fca59cbe4 commit: 28ce410d2aa2eb33d0e61fbf272e1929b734622d Author: Michał Górny gentoo org> AuthorDate: Fri Mar 27 15:14:48 2020 +0000 Commit: Michał Górny gentoo org> CommitDate: Sat Mar 28 18:48:24 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=28ce410d process: Unshare UTS namespace, and set hostname to 'localhost' 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. Closes: https://github.com/gentoo/portage/pull/539 Signed-off-by: Michał Górny gentoo.org> lib/portage/process.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/portage/process.py b/lib/portage/process.py index c1fc4bcf6..590116890 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 = 0x00020000 + CLONE_NEWUTS = 0x04000000 CLONE_NEWIPC = 0x08000000 CLONE_NEWPID = 0x20000000 CLONE_NEWNET = 0x40000000 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,13 @@ def _exec(binary, mycommand, opt_name, fd_pipes, noiselevel=-1) os._exit(1) if unshare_net: + # use 'localhost' to avoid hostname resolution problems + try: + socket.sethostname('localhost') + except Exception as e: + writemsg("Unable to set hostname: %s (for FEATURES=\"network-sandbox\")\n" % ( + e,), + noiselevel=-1) _configure_loopback_interface() except AttributeError: # unshare() not supported by libc