[PATCH] Import portage.util.netlink.RtNetlink in global scope

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

[PATCH] Import portage.util.netlink.RtNetlink in global scope

Mike Gilbert-2
Bug: https://bugs.gentoo.org/718578
Signed-off-by: Mike Gilbert <[hidden email]>
---
 lib/portage/process.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index 590116890..79052b608 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -27,6 +27,13 @@ from portage.const import BASH_BINARY, SANDBOX_BINARY, FAKEROOT_BINARY
 from portage.exception import CommandNotFound
 from portage.util._ctypes import find_library, LoadLibrary, ctypes
 
+try:
+ from portage.util.netlink import RtNetlink
+except ImportError:
+ if platform.system() == "Linux":
+ raise
+ RtNetlink = None
+
 try:
  import resource
  max_fd_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
@@ -504,8 +511,8 @@ def _configure_loopback_interface():
  # Bug: https://bugs.gentoo.org/690758
  # Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13
 
- # Avoid importing this module on systems that may not support netlink sockets.
- from portage.util.netlink import RtNetlink
+ if RtNetlink is None:
+ return
 
  try:
  with RtNetlink() as rtnl:
--
2.26.1


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Import portage.util.netlink.RtNetlink in global scope

Zac Medico-2
On 4/20/20 1:50 PM, Mike Gilbert wrote:

> Bug: https://bugs.gentoo.org/718578
> Signed-off-by: Mike Gilbert <[hidden email]>
> ---
>  lib/portage/process.py | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/lib/portage/process.py b/lib/portage/process.py
> index 590116890..79052b608 100644
> --- a/lib/portage/process.py
> +++ b/lib/portage/process.py
> @@ -27,6 +27,13 @@ from portage.const import BASH_BINARY, SANDBOX_BINARY, FAKEROOT_BINARY
>  from portage.exception import CommandNotFound
>  from portage.util._ctypes import find_library, LoadLibrary, ctypes
>  
> +try:
> + from portage.util.netlink import RtNetlink
> +except ImportError:
> + if platform.system() == "Linux":
> + raise
> + RtNetlink = None
> +
>  try:
>   import resource
>   max_fd_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
> @@ -504,8 +511,8 @@ def _configure_loopback_interface():
>   # Bug: https://bugs.gentoo.org/690758
>   # Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13
>  
> - # Avoid importing this module on systems that may not support netlink sockets.
> - from portage.util.netlink import RtNetlink
> + if RtNetlink is None:
> + return
>  
>   try:
>   with RtNetlink() as rtnl:
>
Looks good. Please merge.
--
Thanks,
Zac


signature.asc (352 bytes) Download Attachment