* [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/, lib/portage/util/, /, lib/portage/
@ 2024-02-26 4:11 Mike Gilbert
0 siblings, 0 replies; only message in thread
From: Mike Gilbert @ 2024-02-26 4:11 UTC (permalink / raw
To: gentoo-commits
commit: 19e27e0415fd321c39104f7d687bcdc4f4132e24
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 25 18:10:15 2024 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Mon Feb 26 04:10:32 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=19e27e04
Add workaround for loading libc on musl
musl libc has no soname, which causes ctypes.util.find_library to fail.
As a fallback, try to load "libc.so".
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
NEWS | 7 +++++++
lib/portage/dbapi/_MergeProcess.py | 4 ++--
lib/portage/dbapi/_SyncfsProcess.py | 14 ++++----------
lib/portage/process.py | 16 +++++-----------
lib/portage/util/_ctypes.py | 15 +++++++++++++++
lib/portage/util/locale.py | 7 ++-----
6 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/NEWS b/NEWS
index eb84651b53..258d800373 100644
--- a/NEWS
+++ b/NEWS
@@ -6,8 +6,15 @@ Release notes take the form of the following optional categories:
* Bug fixes
* Cleanups
+portage-3.0.64 (UNRELEASED)
+--------------
+
+Bug fixes:
+
+
portage-3.0.63 (2024-02-25)
--------------
+* ctypes: Add workaround for loading libc on musl
Bug fixes:
* emerge: Skip installed packages with emptytree in depgraph selection (bug #651018).
diff --git a/lib/portage/dbapi/_MergeProcess.py b/lib/portage/dbapi/_MergeProcess.py
index dd5ad71cf8..d9ab2b47aa 100644
--- a/lib/portage/dbapi/_MergeProcess.py
+++ b/lib/portage/dbapi/_MergeProcess.py
@@ -10,7 +10,7 @@ import fcntl
import portage
from portage import os, _unicode_decode
from portage.package.ebuild._ipc.QueryCommand import QueryCommand
-from portage.util._ctypes import find_library
+from portage.util._ctypes import load_libc
import portage.elog.messages
from portage.util._async.ForkProcess import ForkProcess
from portage.util import no_color
@@ -64,7 +64,7 @@ class MergeProcess(ForkProcess):
# process, so that it's only done once rather than
# for each child process.
if platform.system() == "Linux" and "merge-sync" in settings.features:
- find_library("c")
+ load_libc()
# Inherit stdin by default, so that the pdb SIGUSR1
# handler is usable for the subprocess.
diff --git a/lib/portage/dbapi/_SyncfsProcess.py b/lib/portage/dbapi/_SyncfsProcess.py
index ddc2240071..300ae53985 100644
--- a/lib/portage/dbapi/_SyncfsProcess.py
+++ b/lib/portage/dbapi/_SyncfsProcess.py
@@ -4,7 +4,7 @@
import functools
from portage import os
-from portage.util._ctypes import find_library, LoadLibrary
+from portage.util._ctypes import load_libc
from portage.util._async.ForkProcess import ForkProcess
@@ -24,15 +24,9 @@ class SyncfsProcess(ForkProcess):
@staticmethod
def _get_syncfs():
- filename = find_library("c")
- if filename is not None:
- library = LoadLibrary(filename)
- if library is not None:
- try:
- return library.syncfs
- except AttributeError:
- pass
-
+ (libc, _) = load_libc()
+ if libc is not None:
+ return getattr(libc, "syncfs", None)
return None
@staticmethod
diff --git a/lib/portage/process.py b/lib/portage/process.py
index cc9ed7bf78..b652e32942 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -37,7 +37,7 @@ portage.proxy.lazyimport.lazyimport(
from portage.const import BASH_BINARY, SANDBOX_BINARY, FAKEROOT_BINARY
from portage.exception import CommandNotFound
from portage.proxy.objectproxy import ObjectProxy
-from portage.util._ctypes import find_library, LoadLibrary, ctypes
+from portage.util._ctypes import load_libc, LoadLibrary, ctypes
try:
from portage.util.netlink import RtNetlink
@@ -960,11 +960,9 @@ def _exec(
have_unshare = False
libc = None
if unshare_net or unshare_ipc or unshare_mount or unshare_pid:
- filename = find_library("c")
- if filename is not None:
- libc = LoadLibrary(filename)
- if libc is not None:
- have_unshare = hasattr(libc, "unshare")
+ (libc, _) = load_libc()
+ if libc is not None:
+ have_unshare = hasattr(libc, "unshare")
if not have_unshare:
# unshare() may not be supported by libc
@@ -1212,11 +1210,7 @@ class _unshare_validator:
"""
# This ctypes library lookup caches the result for use in the
# subprocess when the multiprocessing start method is fork.
- filename = find_library("c")
- if filename is None:
- return errno.ENOTSUP
-
- libc = LoadLibrary(filename)
+ (libc, filename) = load_libc()
if libc is None:
return errno.ENOTSUP
diff --git a/lib/portage/util/_ctypes.py b/lib/portage/util/_ctypes.py
index e6d1e327cb..04e965ba92 100644
--- a/lib/portage/util/_ctypes.py
+++ b/lib/portage/util/_ctypes.py
@@ -48,3 +48,18 @@ def LoadLibrary(name):
_library_handles[name] = handle
return handle
+
+
+def load_libc():
+ """
+ Loads the C standard library, returns a tuple with the CDLL handle and
+ the filename. Returns (None, None) if unavailable.
+ """
+ filename = find_library("c")
+ if filename is None:
+ # find_library fails for musl where there is no soname
+ filename = "libc.so"
+ try:
+ return (LoadLibrary(filename), filename)
+ except OSError:
+ return (None, None)
diff --git a/lib/portage/util/locale.py b/lib/portage/util/locale.py
index b6a41e7655..d0edeb4afe 100644
--- a/lib/portage/util/locale.py
+++ b/lib/portage/util/locale.py
@@ -16,7 +16,7 @@ import traceback
import portage
from portage.util import _unicode_decode, writemsg_level
-from portage.util._ctypes import find_library, LoadLibrary
+from portage.util._ctypes import load_libc
from portage.util.futures import asyncio
@@ -46,10 +46,7 @@ def _check_locale(silent):
try:
from portage.util import libc
except ImportError:
- libc_fn = find_library("c")
- if libc_fn is None:
- return None
- libc = LoadLibrary(libc_fn)
+ (libc, _) = load_libc()
if libc is None:
return None
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-26 4:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 4:11 [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/, lib/portage/util/, /, lib/portage/ Mike Gilbert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox