mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Add prophylactic code for bogus environment variables.
Each env-var value should be a string, if not we skip None and convert all other values to strings. But we also log warnings so we can tell which env-var it was.
This commit is contained in:
parent
85e63862f6
commit
ed4e4c32ba
|
@ -7,6 +7,7 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
@ -36,7 +37,6 @@ WRAPPER_SCRIPT = get_wrapper_script_location()
|
||||||
|
|
||||||
|
|
||||||
class MonitoredCommand:
|
class MonitoredCommand:
|
||||||
|
|
||||||
"""Exexcutes a commmand while keeping track of its state"""
|
"""Exexcutes a commmand while keeping track of its state"""
|
||||||
|
|
||||||
fallback_cwd = "/tmp"
|
fallback_cwd = "/tmp"
|
||||||
|
@ -120,14 +120,26 @@ class MonitoredCommand:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_environment(user_env):
|
def get_environment(user_env):
|
||||||
"""Process the user provided environment variables for use as self.env"""
|
"""Process the user provided environment variables for use as self.env"""
|
||||||
env = user_env or {}
|
env = copy(user_env) if user_env else {}
|
||||||
# not clear why this needs to be added, the path is already added in
|
# not clear why this needs to be added, the path is already added in
|
||||||
# the wrappper script.
|
# the wrappper script.
|
||||||
env['PYTHONPATH'] = ':'.join(sys.path)
|
env['PYTHONPATH'] = ':'.join(sys.path)
|
||||||
# Drop bad values of environment keys, those will confuse the Python
|
# Drop bad values of environment keys, those will confuse the Python
|
||||||
# interpreter.
|
# interpreter.
|
||||||
env["LUTRIS_GAME_UUID"] = str(uuid.uuid4())
|
env["LUTRIS_GAME_UUID"] = str(uuid.uuid4())
|
||||||
return {key: value for key, value in env.items() if "=" not in key}
|
|
||||||
|
cleaned = {}
|
||||||
|
for key, value in env.items():
|
||||||
|
if "=" in key:
|
||||||
|
logger.warning("Environment variable name '%s' contains '=' so it can't be used; skipping.", key)
|
||||||
|
elif value is None:
|
||||||
|
logger.warning("Environment variable '%s' has None for its value; skipping.", key)
|
||||||
|
elif not isinstance(value, str):
|
||||||
|
logger.warning("Environment variable '%s' value '%s' is not a string; converting.", key, value)
|
||||||
|
cleaned[key] = str(value)
|
||||||
|
else:
|
||||||
|
cleaned[key] = value
|
||||||
|
return cleaned
|
||||||
|
|
||||||
def get_child_environment(self):
|
def get_child_environment(self):
|
||||||
"""Returns the calculated environment for the child process."""
|
"""Returns the calculated environment for the child process."""
|
||||||
|
|
Loading…
Reference in a new issue