Find the shared library paths from the user's system.
()
| 85 | |
| 86 | @cache |
| 87 | def get_library_paths() -> set[str]: |
| 88 | """Find the shared library paths from the user's system.""" |
| 89 | library_paths: set[str] = set() |
| 90 | paths: set[str] = set() |
| 91 | ldconfig_paths: str = ":".join(filter(None, (os.environ.get("PATH"), "/sbin"))) |
| 92 | ldconfig: str = which("ldconfig", path=ldconfig_paths) or "" |
| 93 | root = "/" |
| 94 | |
| 95 | ldconfig_path = which(ldconfig) |
| 96 | if ldconfig_path is None: |
| 97 | log.warning("ldconfig not found in $PATH, cannot find library paths") |
| 98 | return library_paths |
| 99 | |
| 100 | # Find all shared library path prefixes within the assumptions of the |
| 101 | # Steam Runtime container framework. The framework already works hard by |
| 102 | # attempting to work with various distibutions' quirks. Unless it's Flatpak |
| 103 | # related, let's continue to make it their job. |
| 104 | try: |
| 105 | # Here, opt to using the ld.so cache similar to the stdlib |
| 106 | # implementation of _findSoname_ldconfig. |
| 107 | with Popen( # nosec B603 |
| 108 | (ldconfig_path, "-p"), |
| 109 | text=True, |
| 110 | encoding="utf-8", |
| 111 | stdout=PIPE, |
| 112 | env={"LC_ALL": "C", "LANG": "C"}, |
| 113 | ) as proc: |
| 114 | if not proc.stdout: |
| 115 | return library_paths |
| 116 | for line in proc.stdout: |
| 117 | lines = line.split() |
| 118 | if not lines: |
| 119 | continue |
| 120 | line = lines[-1] |
| 121 | prefix = line[: line.rfind(root)] |
| 122 | if not line.startswith(root) or prefix in paths: |
| 123 | continue |
| 124 | paths.add(prefix) |
| 125 | library_paths.add(os.path.realpath(prefix)) |
| 126 | except OSError as e: |
| 127 | log.exception(e) |
| 128 | |
| 129 | return library_paths |
| 130 | |
| 131 | |
| 132 | def run_zenity(command: str, opts: list[str], msg: str) -> int: |
no test coverage detected