[PR #2305] linux-boot: harden boot-inner.sh and configure-worktree.sh #2309

Open
opened 2026-11-26 21:20:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2305
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/linux-boot-inner-configure-safety


📝 Commits (1)

  • 9a2ac71 linux-boot: harden boot-inner.sh and configure-worktree.sh

📊 Changes

3 files changed (+397 additions, -23 deletions)

View changed files

📝 scripts/linux-boot/boot-inner.sh (+99 -18)
📝 scripts/linux-boot/configure-worktree.sh (+46 -5)
➕ tests/test_linux_boot_inner_and_configure.py (+252 -0)

📄 Description

Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193109369)

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2305 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/linux-boot-inner-configure-safety` --- ### 📝 Commits (1) - [`9a2ac71`](https://github.com/ubiquitarianism/leonida/commit/9a2ac71066ee1cfc23b39c6b4b4b121ed2ab72d0) linux-boot: harden boot-inner.sh and configure-worktree.sh ### 📊 Changes **3 files changed** (+397 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `scripts/linux-boot/boot-inner.sh` (+99 -18) 📝 `scripts/linux-boot/configure-worktree.sh` (+46 -5) ➕ `tests/test_linux_boot_inner_and_configure.py` (+252 -0) </details> ### 📄 Description Claimed in the coordination issue as: LINUX-BOOT-INNER-AND-CONFIGURE-WORKTREE-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193109369) ### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2309
No description provided.