mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-23 06:46:02 +00:00
fix(fex): signal return restores syscall state; CurseForge runs headless (#3040)
* fix(fex): signal return restores the interrupted syscall state A guest rt_sigreturn goes through FEX's syscall stub, which marks every static register as spilled. Returning to unchanged JIT code skipped the stub's reset, so later asynchronous signals skipped the register spill and guest handlers read stale registers. CoreCLR's GC suspension reads and redirects that context, which made x86-64 .NET programs fail with random access violations. Restore the value saved at signal entry. * fix(addons): run CurseForge headless from the addon browser, without a session - The CurseForge source starts the app in its own headless gamescope (droiddeck-headless, shared with the Battle.net Agent) instead of a hidden session: no SessionService, compositor output or ImageReader. - The helper's start keeps running until the app exits, so the app lives for as long as the addon browser holds that guest command; closing the dialog asks the app to quit, stops its process group and cancels the command, which ends the app, its gamescope and the guest. - An app the user already has open is reported busy and left alone. - Removes BackgroundSession and the CompositorHost start path it shared with SessionActivity, with their tests. * fix(addons): bind each CurseForge stop to its launch and keep the inspector URL out of logs A stop now only acts on the launch that registered it, so a late stop from a closed browser cannot end a newer launch, and the browser stops once. Command logs redact the inspector URL. The signal probe reports a sender thread that cannot start, sets ECX before the measured region and its test accepts a valid overshoot of the target count. * fix(fex): unblock the probe signal before sampling
This commit is contained in:
1 parent
6ef8e2274e
commit
527cb85867
21 files changed
+663
-415
No files matched your search
@@ -1206,6 +1206,15 @@ def handle(agent_dir, req):
|
||||
raise AgentError("UNKNOWN_REQUEST", "Unknown agent request '%s'" % kind)
|
||||
|
||||
|
||||
def reply(agent_dir, req):
|
||||
try:
|
||||
return dict(handle(agent_dir, req), ok=True)
|
||||
except AgentError as e:
|
||||
return {"ok": False, "error": {"code": e.code, "message": str(e)}}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": {"code": "AGENT_FAILED", "message": "%s: %s" % (type(e).__name__, e)}}
|
||||
|
||||
|
||||
def answer(agent_dir, path):
|
||||
rid = path.stem
|
||||
try:
|
||||
@@ -1225,12 +1234,7 @@ def answer(agent_dir, path):
|
||||
except OSError:
|
||||
pass
|
||||
if req is not None:
|
||||
try:
|
||||
result = dict(handle(agent_dir, req), ok=True)
|
||||
except AgentError as e:
|
||||
result = {"ok": False, "error": {"code": e.code, "message": str(e)}}
|
||||
except Exception as e:
|
||||
result = {"ok": False, "error": {"code": "AGENT_FAILED", "message": "%s: %s" % (type(e).__name__, e)}}
|
||||
result = reply(agent_dir, req)
|
||||
write_json(agent_dir / "resp" / (rid + ".json"), result)
|
||||
|
||||
|
||||
@@ -1257,6 +1261,13 @@ def serve(agent_dir, focus=True, poll=0.1):
|
||||
|
||||
|
||||
def main(argv):
|
||||
if argv and argv[0] == "--cdp-inspector":
|
||||
if len(argv) != 4:
|
||||
print("usage: droiddeck-agent --cdp-inspector <inspector url> <seconds> <expression>", file=sys.stderr)
|
||||
return 2
|
||||
print(json.dumps(reply(Path("/"), {"kind": "cdp", "inspector": argv[1], "timeout": argv[2],
|
||||
"expression": argv[3], "commandLineApi": True})))
|
||||
return 0
|
||||
base = os.environ.get("DD_LAUNCH_DIR")
|
||||
if not base:
|
||||
print("DD_LAUNCH_DIR is not set", file=sys.stderr)
|
||||
|
||||
@@ -79,8 +79,7 @@ AGENT_START = 90
|
||||
AGENT_HELPER = "agent.js"
|
||||
AGENT_RUNTIME = "agent-runtime"
|
||||
AGENT_LOG = "agent.log"
|
||||
AGENT_LOG_LIMIT = 4 << 20
|
||||
HEADLESS = ["--backend", "headless", "-w", "640", "-h", "480"]
|
||||
HEADLESS = "/usr/local/bin/droiddeck-headless"
|
||||
PRODUCT = re.compile(r"[a-z0-9_]{1,32}")
|
||||
LOCALE = re.compile(r"[a-z]{2}[A-Z]{2}")
|
||||
COUNTRY = re.compile(r"[A-Z]{3}")
|
||||
@@ -1416,33 +1415,23 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
|
||||
windows = install_path(root, folder)
|
||||
emit("STATE", "starting")
|
||||
base = os.path.join(CACHE, "agent-%s" % uid)
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
for suffix in (".json", ".game", ".form", ".error"):
|
||||
try:
|
||||
os.unlink(base + suffix)
|
||||
except OSError:
|
||||
pass
|
||||
runtime = os.path.join(CACHE, AGENT_RUNTIME)
|
||||
os.makedirs(runtime, mode=0o700, exist_ok=True)
|
||||
env = agent_env()
|
||||
for name in ("DISPLAY", "WAYLAND_DISPLAY"):
|
||||
env.pop(name, None)
|
||||
env["XDG_RUNTIME_DIR"] = runtime
|
||||
cmd = ["gamescope"] + HEADLESS + ["--", os.path.abspath(sys.argv[0]), "agent-serve", action, uid, product or "-",
|
||||
windows or "-", locale, country, region, "Z:" + base.replace("/", "\\")]
|
||||
cmd = [HEADLESS, os.path.join(CACHE, AGENT_RUNTIME), "--log", os.path.join(CACHE, AGENT_LOG), "--",
|
||||
os.path.abspath(sys.argv[0]), "agent-serve", action, uid, product or "-",
|
||||
windows or "-", locale, country, region, "Z:" + base.replace("/", "\\")]
|
||||
say("%s %s through the Agent: %s" % (action, uid, " ".join(cmd)))
|
||||
output = os.path.join(CACHE, AGENT_LOG)
|
||||
try:
|
||||
if os.path.getsize(output) > AGENT_LOG_LIMIT:
|
||||
os.replace(output, output + ".1")
|
||||
except OSError:
|
||||
pass
|
||||
before = {pid for pid, _ in wine_processes(pfx)}
|
||||
with open(output, "ab") as log:
|
||||
try:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=log, stderr=log, env=env)
|
||||
except OSError as error:
|
||||
emit("ERROR", "stopped gamescope: %s" % error)
|
||||
return 1
|
||||
try:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=env)
|
||||
except OSError as error:
|
||||
emit("ERROR", "stopped gamescope: %s" % error)
|
||||
return 1
|
||||
seen = None
|
||||
mark = None
|
||||
moved = time.monotonic()
|
||||
|
||||
@@ -5,39 +5,17 @@ self=${BASH_SOURCE[0]}
|
||||
proc=${DD_PROC:-/proc}
|
||||
state=${DD_CURSEFORGE_STATE:-${XDG_RUNTIME_DIR:-/tmp}/droiddeck-curseforge}
|
||||
runner=${DD_APPIMAGE_RUN:-${self%/*}/droiddeck-appimage-run}
|
||||
headless=${DD_HEADLESS_RUN:-${self%/*}/droiddeck-headless}
|
||||
wait_s=${DD_CURSEFORGE_WAIT:-60}
|
||||
cmd=${1:-}
|
||||
dir=${2:-}
|
||||
flag=--inspect-publish-uid=stderr
|
||||
case $cmd in start|hold|stop|display) ;; *) echo "usage: droiddeck-curseforge start|hold|stop|display <imported AppImage directory>" >&2; exit 2 ;; esac
|
||||
if [ "$cmd" != display ] && [ ! -d "$dir/app" ]; then
|
||||
case $cmd in start|stop) ;; *) echo "usage: droiddeck-curseforge start|stop <imported AppImage directory>" >&2; exit 2 ;; esac
|
||||
if [ ! -d "$dir/app" ]; then
|
||||
echo "droiddeck-curseforge: $dir is not an imported AppImage" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
x_display() {
|
||||
if [ -n "${DISPLAY:-}" ]; then
|
||||
printf '%s\n%s\n' "$DISPLAY" "${XAUTHORITY:-}"
|
||||
return 0
|
||||
fi
|
||||
local p name a prev display auth
|
||||
for p in "$proc"/[0-9]*; do
|
||||
name=$(tr '\0' '\n' 2>/dev/null < "$p/cmdline" | head -n 1)
|
||||
case ${name##*/} in Xwayland|Xorg|Xvfb) ;; *) continue ;; esac
|
||||
display= auth= prev=
|
||||
while IFS= read -r a; do
|
||||
case $a in :[0-9]*) [ -z "$display" ] && display=$a ;; esac
|
||||
[ "$prev" = -auth ] && auth=$a
|
||||
prev=$a
|
||||
done < <(tr '\0' '\n' 2>/dev/null < "$p/cmdline")
|
||||
if [ -n "$display" ]; then
|
||||
printf '%s\n%s\n' "$display" "$auth"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
running() {
|
||||
local p
|
||||
for p in "$proc"/[0-9]*; do
|
||||
@@ -79,7 +57,7 @@ inspector() {
|
||||
}
|
||||
|
||||
start() {
|
||||
local shown display auth url pid
|
||||
local url pid child=
|
||||
lock || { echo "droiddeck-curseforge: cannot lock $state" >&2; return 5; }
|
||||
if ! ours >/dev/null; then
|
||||
if tracked >/dev/null || running; then
|
||||
@@ -87,18 +65,18 @@ start() {
|
||||
echo busy
|
||||
return 3
|
||||
fi
|
||||
shown=$(x_display) || { exec 9>&-; echo "no X display" >&2; return 4; }
|
||||
display=$(sed -n 1p <<<"$shown")
|
||||
auth=$(sed -n 2p <<<"$shown")
|
||||
env -u DBUS_SESSION_BUS_ADDRESS -u WAYLAND_DISPLAY -u GAMESCOPE_WAYLAND_DISPLAY DISPLAY="$display" ${auth:+XAUTHORITY="$auth"} \
|
||||
setsid "$runner" "$dir" --minimized --inspect=127.0.0.1:0 "$flag" </dev/null >"$state/log" 2>&1 9>&- &
|
||||
mv -f "$state/log" "$state/log.1" 2>/dev/null
|
||||
env -u DBUS_SESSION_BUS_ADDRESS setsid "$headless" "$state/runtime" --log "$state/log" -- \
|
||||
"$runner" "$dir" --minimized --inspect=127.0.0.1:0 "$flag" </dev/null >/dev/null 2>&1 9>&- &
|
||||
pid=$!
|
||||
child=$pid
|
||||
printf '%s %s %s\n' "$pid" "$(started_at "$pid")" "$dir" > "$state/pid"
|
||||
fi
|
||||
exec 9>&-
|
||||
for _ in $(seq 1 $((wait_s * 2))); do
|
||||
if url=$(inspector); then
|
||||
echo "$url"
|
||||
hold "$child"
|
||||
return 0
|
||||
fi
|
||||
ours >/dev/null || break
|
||||
@@ -108,6 +86,18 @@ start() {
|
||||
return 5
|
||||
}
|
||||
|
||||
hold() {
|
||||
local pid
|
||||
if [ -n "$1" ]; then
|
||||
wait "$1"
|
||||
return 0
|
||||
fi
|
||||
pid=$(ours) || return 0
|
||||
while kill -0 "$pid" 2>/dev/null && [ "$(ours)" = "$pid" ]; do
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
stop() {
|
||||
local pid p
|
||||
lock || return 1
|
||||
@@ -118,6 +108,7 @@ stop() {
|
||||
sleep 0.5
|
||||
done
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
kill -KILL "$pid" 2>/dev/null
|
||||
for p in "$proc"/[0-9]*; do
|
||||
tr '\0' '\n' 2>/dev/null < "$p/cmdline" | grep -qF -- "$dir/app/" && kill -KILL "${p##*/}" 2>/dev/null
|
||||
done
|
||||
@@ -127,22 +118,10 @@ stop() {
|
||||
}
|
||||
|
||||
case $cmd in
|
||||
display)
|
||||
x_display || exit 4
|
||||
;;
|
||||
start)
|
||||
start
|
||||
exit $?
|
||||
;;
|
||||
hold)
|
||||
start >/dev/null || exit $?
|
||||
trap 'stop; exit 0' TERM INT HUP
|
||||
while ours >/dev/null; do
|
||||
sleep 1 &
|
||||
wait $!
|
||||
done
|
||||
exit 0
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
exit 0
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
runtime=${1:-}
|
||||
shift
|
||||
log=
|
||||
if [ "${1:-}" = --log ]; then
|
||||
log=${2:-}
|
||||
shift 2
|
||||
fi
|
||||
if [ -z "$runtime" ] || [ "${1:-}" != -- ] || [ $# -lt 2 ]; then
|
||||
echo "usage: droiddeck-headless <private runtime directory> [--log <file>] -- <command> [args...]" >&2
|
||||
exit 2
|
||||
fi
|
||||
shift
|
||||
umask 077
|
||||
mkdir -p "$runtime" && chmod 700 "$runtime" || exit 1
|
||||
if [ -n "$log" ]; then
|
||||
size=$(stat -c %s "$log" 2>/dev/null || echo 0)
|
||||
[ "$size" -gt "${DD_HEADLESS_LOG_LIMIT:-4194304}" ] && mv -f "$log" "$log.1"
|
||||
exec >>"$log" 2>&1
|
||||
fi
|
||||
unset DISPLAY WAYLAND_DISPLAY GAMESCOPE_WAYLAND_DISPLAY XAUTHORITY
|
||||
export XDG_RUNTIME_DIR=$runtime
|
||||
exec gamescope --backend headless -w 640 -h 480 -- "$@"
|
||||
Reference in new issue
Block a user