Skip to content

Commit

Permalink
Handle dlopen(NULL) failure in glibc fallback (#13)
Browse files Browse the repository at this point in the history
(cherry picked from commit 601bcf8)

Manually removed type annotation added in that commit to keep Python 2.7
support for Pex vendored Pip.

---------

Co-authored-by: Charlie Marsh <crmarsh416@gmail.com>
Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent 386a54f commit 00827ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/12716.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid dlopen failure for glibc detection in musl builds
15 changes: 14 additions & 1 deletion src/pip/_internal/utils/glibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ def glibc_version_string_ctypes():
# manpage says, "If filename is NULL, then the returned handle is for the
# main program". This way we can let the linker do the work to figure out
# which libc our process is actually using.
process_namespace = ctypes.CDLL(None)
#
# We must also handle the special case where the executable is not a
# dynamically linked executable. This can occur when using musl libc,
# for example. In this situation, dlopen() will error, leading to an
# OSError. Interestingly, at least in the case of musl, there is no
# errno set on the OSError. The single string argument used to construct
# OSError comes from libc itself and is therefore not portable to
# hard code here. In any case, failure to call dlopen() means we
# can't proceed, so we bail on our attempt.
try:
process_namespace = ctypes.CDLL(None)
except OSError:
return None

try:
gnu_get_libc_version = process_namespace.gnu_get_libc_version
except AttributeError:
Expand Down

0 comments on commit 00827ec

Please sign in to comment.