From 45aae2ded80227a48ed3319e0160df6c27cc80a6 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Sat, 14 Nov 2026 00:37:27 -0500 Subject: [PATCH] fix(store): run the store exit hook when the session ends a store game --- .../overlay/usr/local/bin/steam-compatibility | 1 + tools/tests/test_store_launch.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index cf616c86fc..0050c167c8 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -86,6 +86,7 @@ bl_run() { set -- /usr/local/bin/droiddeck-steamvr-game "$@" fi if [ -n "${BL_STORE_EXIT:-}" ]; then + trap : INT TERM HUP "$@" rc=$? /usr/local/bin/droiddeck-store-launch --exited --code "$rc" "${BL_STORE_ARGS[@]}" || true diff --git a/tools/tests/test_store_launch.py b/tools/tests/test_store_launch.py index 36a1b7c9a1..ce7c33e305 100644 --- a/tools/tests/test_store_launch.py +++ b/tools/tests/test_store_launch.py @@ -1,6 +1,8 @@ import importlib.machinery import importlib.util import json +import shlex +import subprocess import os from pathlib import Path import tempfile @@ -317,6 +319,33 @@ class Launchers(unittest.TestCase): self.assertIn('bl_store_launch() {', compat.BL_STORE_SETUP) self.assertIn('waitforexitandrun', compat.BL_STORE_SETUP) + def run_store_game(self, game, store_exit=True): + with tempfile.TemporaryDirectory() as root: + hook = Path(root) / 'hook' + record = Path(root) / 'exited' + hook.write_text('#!/bin/sh\necho "$@" > "%s"\n' % record) + hook.chmod(0o755) + setup = compat.BL_STORE_SETUP.replace('/usr/local/bin/droiddeck-store-launch --exited', str(hook) + ' --exited') + script = setup + '\nBL_STORE_ARGS=(game.bat)\n%sbl_run sh -c %s\nexit 99\n' % ( + 'BL_STORE_EXIT=1\n' if store_exit else '', shlex.quote(game)) + done = subprocess.run(['bash', '-c', script], start_new_session=True, timeout=20) + return done.returncode, record.read_text().split() if record.exists() else None + + def test_a_store_game_ended_by_a_group_signal_still_reports_its_exit(self): + for signal_name, code in (('INT', '130'), ('TERM', '143'), ('HUP', '129')): + rc, hook = self.run_store_game('kill -%s 0; sleep 5' % signal_name) + self.assertEqual(['--exited', '--code', code, 'game.bat'], hook, signal_name) + self.assertEqual(int(code), rc, signal_name) + + def test_a_store_game_that_exits_by_itself_reports_its_code_once(self): + self.assertEqual((3, ['--exited', '--code', '3', 'game.bat']), self.run_store_game('exit 3')) + + def test_other_games_still_replace_the_wrapper_without_the_exit_hook(self): + self.assertEqual((4, None), self.run_store_game('exit 4', store_exit=False)) + rc, hook = self.run_store_game('kill -INT 0; sleep 5', store_exit=False) + self.assertIsNone(hook) + self.assertEqual(-2, rc) + if __name__ == '__main__': unittest.main()