Read live game cores from the path the app writes and accept only well-formed lists

The x86-64 client runs with its own HOME, so the reader now uses the fixed guest path the app writes. A list such as 6- keeps the session value instead of reaching taskset.
This commit is contained in:
maxjivi05 committed 2026-11-27 00:12:11 -05:00
1 parent 2a97ecf163
commit 9077704379
2 files changed
+14 -8

No files matched your search

@@ -227,9 +227,9 @@ dd_components() {
DD_GAME_CPUS_SETUP = """
dd_game_cpus() {
local live="${HOME:-/root}/.config/droiddeck/game-cores" cpus
local live=/root/.config/droiddeck/game-cores cpus
if [ -f "$live" ] && cpus=$(<"$live") 2>/dev/null; then
case $cpus in *[!0-9,-]*) cpus=${DD_GAME_CPUS:-} ;; esac
[[ -z $cpus || $cpus =~ ^[0-9]+(-[0-9]+)?(,[0-9]+(-[0-9]+)?)*$ ]] || cpus=${DD_GAME_CPUS:-}
if [ -z "$cpus" ] && [ -n "${DD_CLIENT_CPUS:-}" ]; then
cpus=$(nproc --all 2>/dev/null) && cpus=0-$((cpus - 1)) || cpus=
fi
+12 -6
View File
@@ -14,8 +14,7 @@ class LiveGameCpusTest(unittest.TestCase):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
base = Path(self.temp.name)
self.home = base / "home"
(self.home / ".config/droiddeck").mkdir(parents=True)
self.live = base / "game-cores"
tools = base / "tools"
tools.mkdir()
for name, body in (("taskset", "exit 0"), ("nproc", "echo 8")):
@@ -26,10 +25,11 @@ class LiveGameCpusTest(unittest.TestCase):
def run_setup(self, live=None, **extra):
if live is not None:
(self.home / ".config/droiddeck/game-cores").write_text(live)
script = COMPAT["DD_GAME_CPUS_SETUP"] + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
self.live.write_text(live)
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(HOME=str(self.home), PATH=self.path, **extra)
env.update(PATH=self.path, **extra)
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
@@ -50,7 +50,13 @@ class LiveGameCpusTest(unittest.TestCase):
self.assertEqual(self.run_setup(), ["taskset=", "cpus=unset"])
def test_an_unreadable_value_keeps_the_session_value(self):
self.assertEqual(self.run_setup("3;rm\n", DD_GAME_CPUS="4,5"), ["taskset=taskset -c 4,5", "cpus=4,5"])
for bad in ("3;rm\n", "6-\n", "-3\n", "3,,4\n", "3,\n"):
self.assertEqual(self.run_setup(bad, DD_GAME_CPUS="4,5"), ["taskset=taskset -c 4,5", "cpus=4,5"], bad)
def test_the_file_is_found_whatever_home_the_client_runs_with(self):
self.assertEqual(self.run_setup("6,7\n", DD_GAME_CPUS="3,4,5,6,7", HOME="/root/.droiddeck-x64"),
["taskset=taskset -c 6,7", "cpus=6,7"])
self.assertIn("live=/root/.config/droiddeck/game-cores ", COMPAT["DD_GAME_CPUS_SETUP"])
if __name__ == "__main__":