Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rare/commands/subreaper/subreaper_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from pathlib import Path
from typing import Any, Generator, List

from .util import find_mangohud_bin, find_mangohud_shim

# Constants defined in prctl.h
# See prctl(2) for more details
PR_SET_NAME = 15
Expand Down Expand Up @@ -99,6 +101,12 @@ def signal_handler(sig, frame):
prctl_ret = prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0, 0)
logger.debug("prctl PR_SET_CHILD_SUBREAPER exited with status: %s", prctl_ret)

if os.environ.get("MANGOHUD") == "1":
if mangoshim := find_mangohud_shim():
os.environ["LD_PRELOAD"] = f'{os.environ.get("LD_PRELOAD", "")}:{mangoshim}'
elif mangobin := find_mangohud_bin():
command.insert(0, mangobin)

pid = os.fork() # pylint: disable=E1101
if pid == -1:
logger.error("Fork failed")
Expand Down
39 changes: 39 additions & 0 deletions rare/commands/subreaper/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import shutil
from typing import List


def find_all(name, path) -> List:
result = []
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
return result


def find_mangohud_shim() -> str:
libs = find_all("libMangoHud_shim.so", "/usr")
if 1 > len(libs) > 2:
return ""
if len(libs) == 1:
return libs[0]
ret = []
for left, right in zip(*(lib.split("/") for lib in libs)):
if left == right:
ret.append(left)
elif left.startswith("lib") and right.startswith("lib"):
ret.append("$LIB")
else:
return ""
return "/".join(ret)


def find_mangohud_bin() -> str:
return shutil.which("mangohud")


if __name__ == "__main__":
print(find_mangohud_shim())


__all__ = ["find_mangohud_shim", "find_mangohud_bin"]
Loading