Skip to content

Commit

Permalink
perf: improve shared library path search (#337)
Browse files Browse the repository at this point in the history
* umu_util: improve shared library paths search

* umu_util: fix mypy
  • Loading branch information
R1kaB3rN authored Jan 15, 2025
1 parent 2b4eb95 commit dcf4cd2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions umu/umu_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def get_libc() -> str:
def get_library_paths() -> set[str]:
"""Find the shared library paths from the user's system."""
library_paths: set[str] = set()
paths: set[str] = set()
ldconfig: str = which("ldconfig") or ""
root = "/"

if not ldconfig:
log.warning("ldconfig not found in $PATH, cannot find library paths")
Expand All @@ -81,15 +83,20 @@ def get_library_paths() -> set[str]:
text=True,
encoding="utf-8",
stdout=PIPE,
stderr=PIPE,
env={"LC_ALL": "C", "LANG": "C"},
) as proc:
stdout, _ = proc.communicate()
library_paths |= {
os.path.realpath(line[: line.rfind("/")])
for line in stdout.split()
if line.startswith("/")
}
if not proc.stdout:
return library_paths
for line in proc.stdout:
lines = line.split()
if not line:
continue
line = lines[-1]
prefix = line[: line.rfind(root)]
if not line.startswith(root) or prefix in paths:
continue
paths.add(prefix)
library_paths.add(os.path.realpath(prefix))
except OSError as e:
log.exception(e)

Expand Down

0 comments on commit dcf4cd2

Please sign in to comment.