use ldconfig for gamemodepath and LIB for gamemodeauto

This commit is contained in:
Nbiba Bedis 2018-11-09 15:05:59 +01:00 committed by Mathieu Comandon
parent a51a017b6f
commit 1d6ee4cc22
3 changed files with 18 additions and 14 deletions

View file

@ -398,7 +398,7 @@ class Game(GObject.Object):
if gamemode:
env['LD_PRELOAD'] = ':'.join([
path for path in
[env.get('LD_PRELOAD'), system.GAMEMODE_PATH]
[env.get('LD_PRELOAD'), "/usr/$LIB/libgamemodeauto.so.0"]
if path
])

View file

@ -105,8 +105,8 @@ system_options = [ # pylint: disable=invalid-name
{
'option': 'gamemode',
'type': 'bool',
'default': bool(system.GAMEMODE_PATH),
'condition': bool(system.GAMEMODE_PATH),
'default': bool(system.find_lib("libgamemodeauto.so.0")),
'condition': bool(system.find_lib("libgamemodeauto.so.0")),
'label': 'Enable Feral gamemode',
'help': 'Request a set of optimisations be temporarily applied to the host OS'
},

View file

@ -46,17 +46,6 @@ INSTALLED_TERMINALS = []
# Detect if system is 64bit capable
IS_64BIT = sys.maxsize > 2**32
# Path to Feral gamemode library
GAMEMODE_PATH = next(
(
path for path in map(
lambda x: os.path.join(x, 'libgamemodeauto.so'),
['/usr/lib/x86_64-linux-gnu', '/usr/lib']
) if os.path.exists(path)
),
None
)
def execute(command, env=None, cwd=None, log_errors=False, quiet=False, shell=False):
"""
@ -455,3 +444,18 @@ def is_running(process):
if re.search(process, x):
return True
return False
def find_lib(libname):
"""Returns a list of absoulte paths found in the system of a given library"""
lib_paths = []
ldconfig_cmd = find_executable("ldconfig")
if ldconfig_cmd:
ldconfig_out = subprocess.check_output(
[ldconfig_cmd, "-p"]).decode("UTF-8")
for out in ldconfig_out.splitlines():
if libname in out:
lib_paths.append(out.split("=> ")[1])
else:
logger.error("ldconfig not found, can't search for lib %s", libname)
return lib_paths