Skip to content

Commit

Permalink
util.py: Programmatically locate ldconfig using shutil.which to h…
Browse files Browse the repository at this point in the history
…andle systems where it's not in the standard PATH.

Additionally use `subprocess.run` with explicit encoding handling to reliably capture `ldconfig` output, addressing potential encoding issues outside the Steam Runtime.
  • Loading branch information
ProjectSynchro committed Sep 22, 2024
1 parent 0f2120e commit 3b9ed4d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,27 @@ def patch_libcuda() -> bool:
os.makedirs(cache_dir, exist_ok=True)

try:
# Use ldconfig -p to search library paths
# Use shutil.which to find ldconfig binary
ldconfig_path = shutil.which('ldconfig')
if not ldconfig_path:
log.warn('ldconfig not found in PATH.')
return False

# Use subprocess.run with explicit encoding handling
try:
output = subprocess.check_output(['ldconfig', '-p'], stderr=subprocess.STDOUT, text=True)
result = subprocess.run(
[ldconfig_path, '-p'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True
)
# Decode the output using utf-8 with fallback to locale preferred encoding
try:
output = result.stdout.decode('utf-8')
except UnicodeDecodeError:
import locale
encoding = locale.getpreferredencoding(False)
output = result.stdout.decode(encoding, errors='replace')
except subprocess.CalledProcessError as e:
log.warn(f'Error running ldconfig: {e}')
return False
Expand Down

0 comments on commit 3b9ed4d

Please sign in to comment.