[PATCH] process: Provide libc fallback for sethostname() on PyPy

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] process: Provide libc fallback for sethostname() on PyPy

Michał Górny-5
Signed-off-by: Michał Górny <[hidden email]>
---
 lib/portage/process.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index 79052b608..ceb454030 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -715,7 +715,14 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
  if unshare_net:
  # use 'localhost' to avoid hostname resolution problems
  try:
- socket.sethostname('localhost')
+ # pypy3 does not implement socket.sethostname()
+ new_hostname = b'localhost'
+ if hasattr(socket, 'sethostname'):
+ socket.sethostname(new_hostname)
+ else:
+ if libc.sethostname(new_hostname, len(new_hostname)) != 0:
+ errno_value = ctypes.get_errno()
+ raise OSError(errno_value, os.strerror(errno_value))
  except Exception as e:
  writemsg("Unable to set hostname: %s (for FEATURES=\"network-sandbox\")\n" % (
  e,),
--
2.26.2


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] process: Provide libc fallback for sethostname() on PyPy

Zac Medico-2
On 5/17/20 1:56 AM, Michał Górny wrote:

> Signed-off-by: Michał Górny <[hidden email]>
> ---
>  lib/portage/process.py | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lib/portage/process.py b/lib/portage/process.py
> index 79052b608..ceb454030 100644
> --- a/lib/portage/process.py
> +++ b/lib/portage/process.py
> @@ -715,7 +715,14 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
>   if unshare_net:
>   # use 'localhost' to avoid hostname resolution problems
>   try:
> - socket.sethostname('localhost')
> + # pypy3 does not implement socket.sethostname()
> + new_hostname = b'localhost'
> + if hasattr(socket, 'sethostname'):
> + socket.sethostname(new_hostname)
> + else:
> + if libc.sethostname(new_hostname, len(new_hostname)) != 0:
> + errno_value = ctypes.get_errno()
> + raise OSError(errno_value, os.strerror(errno_value))
>   except Exception as e:
>   writemsg("Unable to set hostname: %s (for FEATURES=\"network-sandbox\")\n" % (
>   e,),
>
Looks good. Please merge.
--
Thanks,
Zac


signature.asc (1000 bytes) Download Attachment