…- kill the pid list one at a time, sparing both (engine#3361)
rc.shutdown's stray-unmount loop (woof-CE rc.shutdown, the "Karl Godt: 2013-12-14 reworked the whole unmount block"
section) runs `busybox fuser -k -m "$MOUNT_POINT"` for every stray mount, /data included, with no exclusion of $$ or
$PPID, and busybox fuser's default signal is KILL. Puppy's /sbin/poweroff runs /etc/rc.d/rc.shutdown as a child and only
afterwards calls /bin/busybox reboot (read on the rc1 image: /sbin/poweroff line 48 is the /etc/rc.d/rc.shutdown call,
line 63 is `reboot) /bin/busybox reboot`). The 23-24 Nov board-run reboots were started from a /data cwd
(`cd /data/dev/cl-release && ... /sbin/reboot`), so poweroff and rc.shutdown both held /data: fuser killed rc.shutdown
and its caller in the same second, nothing was left to call busybox reboot, and the box sat half shut down until
Ctrl-Alt-Del (three rc1 board-run reboots, engine#3361; the timer/C-state reading was retracted).
- os/v3/puppy/hook-rc-shutdown.sh: replaces that one line (verbatim: ` [ "$xFUSER" ] && busybox fuser -k -m
"$MOUNT_POINT"`) with a kill of the `fuser -m` pid list one pid at a time, skipping rc.shutdown ($$), its caller
($PPID) and the console shell, as woof-CE's own ONEBAD loop below already does; a digits-only guard drops any other
token. The console shell's pid is read with `sed -e "s/^ *//"` because busybox ps right-aligns the pid under its
header (` 1 root 0:00 /bin/busybox init` on the rc1 image): measured on the box, the ONEBAD idiom
`s%^ %%g` removes one leading space and its `cut` then reads an empty pid from such a row. The hook now REFUSES
(exit 1) when that line is not in the file exactly once, instead of shipping an image with the bug; a second run is
byte-identical.
- tests/rc_shutdown_stray_test.sh (new, ctest rc_shutdown_stray, registered in cmake/tests-rc-shutdown.cmake): runs the
loop on a real process tree with a directory standing in for /data - no mount, no root, no reboot. A busybox stub
answers `fuser -m DIR` with the tree's pids that use it (space-separated, numeric pid order like fuser's /proc walk)
and records a reached `reboot`; a ps stub prints the appliance's right-aligned rows. Control (the line as woof-CE
ships it): the caller is SIGKILLed and busybox reboot is never reached, rc.shutdown is killed before its end, the
console shell is killed too. Fixed: rc.shutdown runs to its end, the caller survives and reaches busybox reboot, the
console shell is spared, and a process that only used the mount is still SIGKILLed. dash and busybox ash each run
both. The fixture reaches the stubs through shell functions because the appliance's busybox ash resolves `busybox`
and `ps` as its own applets and never looks at PATH (measured: `command -v busybox` is `busybox` there).
- tests/shutdown_watch_test.sh: its two hook fixtures now carry the stray-unmount kill line the hook patches, because
the hook refuses without it. No assertion changed - the added lines go after the lines it checks by number.
- os/v3/puppy/README.md: the hook row says what engine#3361 adds.
Evidence:
- ctest: `ctest --test-dir build -R rc_shutdown_stray` -> 1/1 Passed (1.20 s); the test prints 36/36 ok on this branch
(`sh tests/rc_shutdown_stray_test.sh`, exit 0).
- control, pre-fix tree: `git worktree add --detach <scratch> origin/main`, new test copied in, run there -> exit 1,
24 ok / 12 FAIL, among them `FAIL fixed-control-dash: the caller survived rc.shutdown and reached busybox reboot`,
`FAIL fixed-control-dash: rc.shutdown ran to its end` and `FAIL fixed-control-dash: the console shell was spared`
(the same three under busybox ash, plus `FAIL the patch is marked in the file` and the other hook rows).
- the real file: `ssh strixhalo cat /etc/rc.d/rc.shutdown` (installed rc1, 17456 B) -> branch hook exit 0, diff is
exactly the stray-loop hunk (the #3287/#3401 marks are already in that file), a second run is unchanged,
`busybox ash -n` ok, `grep -c` of the old line 0 and of the new mark 1.
- `ctest --test-dir build -R shutdown_watch`: 1 row red, `FAIL it runs from its tmpfs copy, as init's child
(detached)`; reproduced identically on the clean origin/main reference tree /home/bcloud/wt/engine-main, so it is
pre-existing on this host, not this change; every other row of that test passes here and on main.
- gate: `scripts/pre-pr-checks.sh --tree-only --base origin/main` -> all 16 check(s) green, 2 skipped, 0 could not be
told, 2 open-PR row(s) not run (--tree-only); skipped are hip_f16_audit and kernel_id_selftest, both "no
gpu-kernels tree".
Not measured here: the reboot half (a board reboot started from a /data cwd with a model loaded, 3/3 with no second
rc.shutdown and no multi-minute gap). That needs the owner-window reboot; nothing was rebooted for this change.
Co-authored-by: bong-water-water-bong <[email protected]>
What was wrong
rc.shutdown's stray-unmount loop (woof-CE rc.shutdown, the "Karl Godt: 2013-12-14 reworked the whole unmount block" section) runs, for every stray mount including /data:
with no exclusion of $$ or $PPID, and busybox fuser's default signal is KILL. Puppy's /sbin/poweroff runs /etc/rc.d/rc.shutdown as a child and only afterwards calls /bin/busybox reboot (read on the rc1 image: /sbin/poweroff line 48 is the /etc/rc.d/rc.shutdown call, line 63 is
reboot) /bin/busybox reboot). The 23-24 Nov board-run reboots were started from a /data cwd (cd /data/dev/cl-release && ... /sbin/reboot), so poweroff and rc.shutdown both held /data. fuser killed rc.shutdown and its caller in the same second, nothing was left to call busybox reboot, and the box sat half shut down until Ctrl-Alt-Del (three rc1 board-run reboots; the timer/C-state reading was retracted in the issue).The change
sed -e "s/^ *//"because busybox ps right-aligns the pid under its header (1 root 0:00 /bin/busybox initon the rc1 image); measured on the box with its own busybox, the ONEBAD idioms%^ %%gstrips one leading space and its cut then reads an empty pid from a padded row. The hook now REFUSES (exit 1) when that line is not in the file exactly once, instead of shipping an image with the bug; a second run is byte-identical. The replacement is done with a read/printf/cat pass, not sed -i, so rc.shutdown keeps its mode (poweroff execs it).command -v busyboxisbusyboxthere), so a PATH stub is not enough.Control: pre-fix tree (origin/main) vs this branch
Pre-fix tree (throwaway
git worktree add --detach <scratch> origin/main, the new test copied in; its hook has no #3361 patch:grep -c STRAYSHID os/v3/puppy/hook-rc-shutdown.sh-> 0):This branch:
The real file
Rows
sh tests/rc_shutdown_stray_test.sh; dash arm always, busybox-ash arm when the box has busybox (the CI image installs none, so that arm prints a skip there, as shutdown_watch's own ash arm already does - on this host it runs and passes).FAIL it runs from its tmpfs copy, as init's child (detached), and it is red on origin/main too - run on the clean reference tree /home/bcloud/wt/engine-main: same single FAIL, everything else passes. It is pre-existing on this host, not this change.Gate
The 2 skipped are hip_f16_audit and kernel_id_selftest, both "no gpu-kernels tree ($GPU_KERNELS_DIR unset, no third_party/gpu-kernels)".
Not verified - and why this PR says Refs, not Closes
The reboot half is not measured here: a board reboot started from a /data cwd with a model loaded, 3/3 with no second rc.shutdown and no multi-minute gap. That is the issue's closure criterion and needs the owner-window reboot; nothing was rebooted for this change. Refs #3361.
Review risk, first
Refs #3361