linux-boot: harden boot-inner.sh and configure-worktree.sh #2305

Open
github-bot wants to merge 1 commit from github-bot/gh-2305 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 13:20 UTC · original
kirigayakazima:fix/linux-boot-inner-configure-safety → main · +397 −23 · 3 files · 1 commits · open

Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (#1608)

What and why

  • Harden scripts/linux-boot/boot-inner.sh:
    • Validate required environment variables (BOOT_AGENT, BOOT_N, BOOT_SECS, GTA6RT) upfront (single path segment checks for BOOT_AGENT/BOOT_N, non-negative integer checks for BOOT_SECS/WAIT_ITERS/LEONIDA_BOOT_MIN_FREE_MB) with exit code 2 before creating or truncating files, and mkdir -p work/root directories before opening logs or locks.
    • Guard flock with command -v flock, select the cgroup v2 0:: entry cleanly from /proc/self/cgroup, coerce non-digit cgroup values such as "max" to 0 via read_uint() before shell arithmetic, and register a signal-safe cleanup() trap (EXIT, INT, TERM) to reap the background sampler subshell immediately.
    • Preserve production defaults while supporting LEONIDA_BOOT_ROOT, LEONIDA_BOOT_WORK, BOOT_SH, NVIDIA_SMI, LEONIDA_MEMINFO_PATH, LEONIDA_SELF_CGROUP_PATH, LEONIDA_CGROUP_ROOT, LEONIDA_WAIT_SLEEP_SECS, LEONIDA_SAMPLE_SLEEP_SECS, and LEONIDA_WAIT_ITERS overrides for testing.
  • Harden scripts/linux-boot/configure-worktree.sh:
    • Support -h/--help (exit 0), validate argument count, worktree directory existence, runtime/CMakeLists.txt, runtime/cmake/clang-cl-xwin.cmake, CMAKE executable availability, and optional SDL3_SRC directory upfront with exit code 2.
    • Pass CMake options via a quoted cmake_args array so paths and SDL3_SRC containing spaces remain intact single argv tokens instead of undergoing unquoted word splitting.
  • Add standard-library unit tests in tests/test_linux_boot_inner_and_configure.py (verifying LF line endings, bash -n syntax, validation exits, cgroup "max" sampling, exit 124 mapping, and spaced worktree/SDL3_SRC paths).

Tested

  • python -I tests/test_linux_boot_inner_and_configure.py -v (via Git Bash): 4 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 8 subtest/test failures).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tests/test_linux_boot_inner_and_configure.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kirigayakazima** on GitHub · 2026-11-26 13:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2305) `kirigayakazima:fix/linux-boot-inner-configure-safety` → `main` · +397 −23 · 3 files · 1 commits · open Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Harden `scripts/linux-boot/boot-inner.sh`: - Validate required environment variables (`BOOT_AGENT`, `BOOT_N`, `BOOT_SECS`, `GTA6RT`) upfront (single path segment checks for `BOOT_AGENT`/`BOOT_N`, non-negative integer checks for `BOOT_SECS`/`WAIT_ITERS`/`LEONIDA_BOOT_MIN_FREE_MB`) with exit code `2` before creating or truncating files, and `mkdir -p` work/root directories before opening logs or locks. - Guard `flock` with `command -v flock`, select the cgroup v2 `0::` entry cleanly from `/proc/self/cgroup`, coerce non-digit cgroup values such as `"max"` to `0` via `read_uint()` before shell arithmetic, and register a signal-safe `cleanup()` trap (`EXIT`, `INT`, `TERM`) to reap the background sampler subshell immediately. - Preserve production defaults while supporting `LEONIDA_BOOT_ROOT`, `LEONIDA_BOOT_WORK`, `BOOT_SH`, `NVIDIA_SMI`, `LEONIDA_MEMINFO_PATH`, `LEONIDA_SELF_CGROUP_PATH`, `LEONIDA_CGROUP_ROOT`, `LEONIDA_WAIT_SLEEP_SECS`, `LEONIDA_SAMPLE_SLEEP_SECS`, and `LEONIDA_WAIT_ITERS` overrides for testing. - Harden `scripts/linux-boot/configure-worktree.sh`: - Support `-h`/`--help` (exit `0`), validate argument count, worktree directory existence, `runtime/CMakeLists.txt`, `runtime/cmake/clang-cl-xwin.cmake`, `CMAKE` executable availability, and optional `SDL3_SRC` directory upfront with exit code `2`. - Pass CMake options via a quoted `cmake_args` array so paths and `SDL3_SRC` containing spaces remain intact single argv tokens instead of undergoing unquoted word splitting. - Add standard-library unit tests in `tests/test_linux_boot_inner_and_configure.py` (verifying LF line endings, `bash -n` syntax, validation exits, cgroup `"max"` sampling, exit `124` mapping, and spaced worktree/`SDL3_SRC` paths). ### Tested - `python -I tests/test_linux_boot_inner_and_configure.py -v` (via Git Bash): 4 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 8 subtest/test failures). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tests/test_linux_boot_inner_and_configure.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:20:40 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2305/head:github-bot/gh-2305'
git switch 'github-bot/gh-2305'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2305'
git switch 'github-bot/gh-2305'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2305'
git switch 'github-bot/gh-2305'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2305'
git switch 'main'
git merge --squash 'github-bot/gh-2305'
git switch 'main'
git merge --ff-only 'github-bot/gh-2305'
git switch 'main'
git merge 'github-bot/gh-2305'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.