diff --git a/xpra/net/subprocess_wrapper.py b/xpra/net/subprocess_wrapper.py index 71f0d8a74a..49e6ae3b90 100644 --- a/xpra/net/subprocess_wrapper.py +++ b/xpra/net/subprocess_wrapper.py @@ -10,8 +10,8 @@ from typing import Any from xpra.gtk.signals import register_os_signals -from xpra.util.str_fn import csv, repr_ellipsized, bytestostr, hexstr -from xpra.util.env import envint, envbool +from xpra.util.str_fn import csv, repr_ellipsized, hexstr +from xpra.util.env import envint, envbool, get_exec_env from xpra.net.bytestreams import TwoFileConnection from xpra.net.common import ConnectionClosedException, PACKET_TYPES from xpra.net.protocol.socket_handler import SocketProtocol @@ -310,19 +310,10 @@ def exec_kwargs() -> dict[str, Any]: return kwargs -def exec_env(blacklist=("LS_COLORS",)) -> dict[str, str]: - env = os.environ.copy() +def exec_env() -> dict[str, str]: + env = get_exec_env() env["XPRA_SKIP_UI"] = "1" env["XPRA_FORCE_COLOR_LOG"] = "1" - # let's make things more complicated than they should be: - # on win32, the environment can end up containing unicode, and subprocess chokes on it - for k, v in env.items(): - if k in blacklist: - continue - try: - env[k] = bytestostr(v.encode("utf8")) - except Exception: - env[k] = bytestostr(v) return env diff --git a/xpra/scripts/main.py b/xpra/scripts/main.py index f7088921d0..e1494ee73f 100755 --- a/xpra/scripts/main.py +++ b/xpra/scripts/main.py @@ -25,7 +25,7 @@ from xpra.common import SocketState, noerr, noop from xpra.util.objects import typedict from xpra.util.str_fn import nonl, csv, print_nested_dict, pver, sorted_nicely, bytestostr -from xpra.util.env import envint, envbool, osexpand, save_env, OSEnvContext +from xpra.util.env import envint, envbool, osexpand, save_env, get_exec_env, OSEnvContext from xpra.util.thread import set_main_thread from xpra.exit_codes import ExitCode, ExitValue, RETRY_EXIT_CODES, exit_str from xpra.os_util import ( @@ -1833,7 +1833,7 @@ def run_opengl_probe(): from xpra.platform.paths import get_nodock_command log = Logger("opengl") cmd = get_nodock_command() + ["opengl"] - env = os.environ.copy() + env = get_exec_env() if is_debug_enabled("opengl"): cmd += ["-d", "opengl"] else: @@ -1841,6 +1841,7 @@ def run_opengl_probe(): env["XPRA_HIDE_DOCK"] = "1" env["XPRA_REDIRECT_OUTPUT"] = "0" start = monotonic() + log(f"run_opengl_probe() using cmd={cmd} with env={env}") try: proc = Popen(cmd, stdout=PIPE, stderr=PIPE, env=env, universal_newlines=True) except Exception as e: diff --git a/xpra/util/env.py b/xpra/util/env.py index c14e48fe83..8804c86727 100644 --- a/xpra/util/env.py +++ b/xpra/util/env.py @@ -248,6 +248,22 @@ def get_saved_env_var(var, default=None): return _saved_env.get(var, default) +def get_exec_env(remove=("LS_COLORS", "LESSOPEN", "HISTCONTROL", "HISTSIZE", )) -> dict[str, str]: + # let's make things more complicated than they should be: + # on win32, the environment can end up containing unicode, and subprocess chokes on it + env: dict[str, str] = {} + for k, v in os.environ.items(): + if k in remove: + continue + try: + env[k] = v.encode("utf8").decode("latin1") + except UnicodeError: + env[k] = str(v) + env["XPRA_SKIP_UI"] = "1" + env["XPRA_FORCE_COLOR_LOG"] = "1" + return env + + class SilenceWarningsContext(AbstractContextManager): def __init__(self, *categories):