mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix(desktop): preserve bounded Windows program diagnostics (#2695)
* fix(desktop): preserve bounded Windows program diagnostics * fix(desktop): isolate stderr mirror failures from diagnostic file capture * fix(desktop): continue stderr mirroring after diagnostic file limit * fix(desktop): make diagnostic stderr messages best-effort
This commit is contained in:
1 parent
eb5aa7a536
commit
868207baf8
7 files changed
+214
-22
No files matched your search
@@ -1234,25 +1234,7 @@ def wait_for(check, timeout, step=0.1):
|
||||
|
||||
|
||||
def capped_log(path):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
handle = open(path, "wb")
|
||||
read, write = os.pipe()
|
||||
|
||||
def pump():
|
||||
written = 0
|
||||
with os.fdopen(read, "rb") as source:
|
||||
while True:
|
||||
chunk = source.read1(65536) if hasattr(source, "read1") else source.read(65536)
|
||||
if not chunk:
|
||||
break
|
||||
if written < LOG_CAP:
|
||||
handle.write(chunk[:LOG_CAP - written])
|
||||
handle.flush()
|
||||
written += len(chunk)
|
||||
handle.close()
|
||||
|
||||
threading.Thread(target=pump, daemon=True).start()
|
||||
return write
|
||||
return GAME_DEBUG["capped_log"](path, LOG_CAP)[0]
|
||||
|
||||
|
||||
class Session:
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#!/usr/bin/python3
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
GAME_DEBUG_CHANNELS = (
|
||||
@@ -69,3 +72,74 @@ def apply_game_debug_logs(env, config=None, debug_dir=None):
|
||||
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
def capped_log(path, limit, mirror=False):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
handle = open(path, "wb")
|
||||
try:
|
||||
read, write = os.pipe()
|
||||
except OSError:
|
||||
handle.close()
|
||||
raise
|
||||
|
||||
def pump():
|
||||
remaining = limit
|
||||
mirror_ok = mirror
|
||||
with os.fdopen(read, "rb") as source, handle:
|
||||
while True:
|
||||
chunk = source.read1(65536)
|
||||
if not chunk:
|
||||
break
|
||||
saved = chunk[:remaining]
|
||||
remaining -= len(saved)
|
||||
if saved:
|
||||
try:
|
||||
handle.write(saved)
|
||||
handle.flush()
|
||||
except (OSError, ValueError):
|
||||
remaining = 0
|
||||
if mirror_ok:
|
||||
try:
|
||||
sys.stderr.write(chunk.decode("utf-8", "replace"))
|
||||
sys.stderr.flush()
|
||||
except (OSError, ValueError):
|
||||
mirror_ok = False
|
||||
|
||||
thread = threading.Thread(target=pump, daemon=True)
|
||||
thread.start()
|
||||
return write, thread
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def desktop_program_logs(env):
|
||||
program = env.get("DROIDDECK_DESKTOP_PROGRAM")
|
||||
if program:
|
||||
env = dict(env)
|
||||
env.pop("DROIDDECK_DESKTOP_PROGRAM", None)
|
||||
if not program or env.get("PROTON_LOG", "0") not in ("", "0"):
|
||||
yield env, None
|
||||
return
|
||||
folder = session_debug_dir(env)
|
||||
try:
|
||||
if not os.path.isabs(folder) or not os.path.isdir(folder):
|
||||
raise OSError("session log directory unavailable")
|
||||
fd, path = tempfile.mkstemp(prefix="desktop-program-", suffix=".log", dir=folder)
|
||||
os.close(fd)
|
||||
output, thread = capped_log(path, 1024 * 1024, mirror=True)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: desktop diagnostics unavailable (%s)" % error, file=sys.stderr)
|
||||
yield env, None
|
||||
return
|
||||
try:
|
||||
if env.get("WINEDEBUG", "-all") in ("", "-all"):
|
||||
env["WINEDEBUG"] = "-all,err+all,+mscoree,+loaddll"
|
||||
try:
|
||||
print("droiddeck-game-env: desktop program %s; first 1048576 diagnostic bytes: %s" % (program, path),
|
||||
file=sys.stderr, flush=True)
|
||||
except OSError:
|
||||
pass
|
||||
yield env, output
|
||||
finally:
|
||||
os.close(output)
|
||||
thread.join(timeout=1)
|
||||
@@ -1178,11 +1178,22 @@ def diagnostic_game_exit(app_id, raw_code, source=None, wrapper_status=None):
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None, diagnostic_app_id=None):
|
||||
with GAME_DEBUG["desktop_program_logs"](launch_env) as (env, output):
|
||||
code = start_process(launch, env, digest, after, diagnostic_app_id, output)
|
||||
if output is not None:
|
||||
try:
|
||||
print("droiddeck-game-env: desktop program exited with status %d" % code, file=sys.stderr, flush=True)
|
||||
except OSError:
|
||||
pass
|
||||
return code
|
||||
|
||||
|
||||
def start_process(launch, launch_env, digest, after=None, diagnostic_app_id=None, output=None):
|
||||
if len(launch) > 1 and launch[1] == "waitforexitandrun":
|
||||
ubisoft_composition_off(launch[0], launch_env)
|
||||
launch, launch_env = system_graphics_launch(launch, launch_env)
|
||||
if after or diagnostic_app_id is not None:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
if after or diagnostic_app_id is not None or output is not None:
|
||||
process = subprocess.Popen(launch, env=launch_env, stderr=output)
|
||||
if diagnostic_app_id is not None:
|
||||
diagnostic_game_event("game_start", diagnostic_app_id)
|
||||
try:
|
||||
|
||||
@@ -417,7 +417,7 @@ def main(argv):
|
||||
say("%s: %s" % (cmd[0], error))
|
||||
if status != 0 and time.monotonic() - started < QUICK_FAILURE:
|
||||
notify("%s did not start" % os.path.basename(path),
|
||||
"It exited with status %d; the session's desktop.log says why." % status)
|
||||
"desktop.log (%d)" % status)
|
||||
if what == "windows":
|
||||
try:
|
||||
subprocess.call([sys.executable, PROGRAMS])
|
||||
|
||||
@@ -524,6 +524,8 @@ def main(argv):
|
||||
os.makedirs(target.compatdata, exist_ok=True)
|
||||
env = environment(os.environ, target, folder, root, window, game_id)
|
||||
env.update(extra)
|
||||
if app is None and verb == VERB:
|
||||
env["DROIDDECK_DESKTOP_PROGRAM"] = program
|
||||
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
|
||||
", without the Steam client" if app is not None else ""))
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user