Skip to content

1bit OS: stray-unmount fuser -k SIGKILLed rc.shutdown and its caller - kill the list per pid, sparing both (engine#3361) - #3470

Merged
bong-water-water-bong merged 1 commit into
mainfrom
fix/3361-stray-unmount-fuser
Nov 24, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
fix/3361-stray-unmount-fuser

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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:

xFUSER=`busybox fuser -m "$MOUNT_POINT" 2>/dev/null`
[ "$xFUSER" ] && busybox fuser -k -m "$MOUNT_POINT"

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

  • os/v3/puppy/hook-rc-shutdown.sh - replaces that one line (matched verbatim, two-space indent as the rc1 image has it) 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 with its own busybox, the ONEBAD idiom s%^ %%g strips 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).
  • tests/rc_shutdown_stray_test.sh (new) - runs the loop on a real process tree with a plain 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/ps as its own applets and never looks at PATH (measured: command -v busybox is busybox there), so a PATH stub is not enough.
  • cmake/tests-rc-shutdown.cmake (new) - registers ctest row rc_shutdown_stray.
  • 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.

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):

$ sh tests/rc_shutdown_stray_test.sh
FAIL the patch is marked in the file
FAIL the one-line fuser -k -m is gone
FAIL the per-pid kill skips rc.shutdown, its caller and the console shell
FAIL the console shell's pid is read from the padded ps row
FAIL an rc.shutdown whose stray-unmount line moved is refused (exit 1)
FAIL and the refused file is left as it was
...
FAIL fixed-control-dash: the caller survived rc.shutdown and reached busybox reboot
FAIL fixed-control-dash: rc.shutdown ran to its end
FAIL fixed-control-dash: the console shell was spared
...
FAIL fixed-control-busybox-ash: the caller survived rc.shutdown and reached busybox reboot
FAIL fixed-control-busybox-ash: rc.shutdown ran to its end
FAIL fixed-control-busybox-ash: the console shell was spared
rc_shutdown_stray_test: FAIL
24 ok / 12 FAIL, exit 1

This branch:

$ ctest --test-dir build -R rc_shutdown_stray --output-on-failure
1/1 Test #468: rc_shutdown_stray ...............   Passed    1.20 sec
100% tests passed, 0 tests failed out of 1

$ sh tests/rc_shutdown_stray_test.sh    # 36 ok / 0 FAIL, exit 0
rc_shutdown_stray_test: ok

The real file

$ ssh strixhalo cat /etc/rc.d/rc.shutdown > rc.shutdown.rc1   # installed rc1, 17456 B
$ sh os/v3/puppy/hook-rc-shutdown.sh rc.shutdown.rc1
hook exit=0
$ diff -u rc.shutdown.rc1.before rc.shutdown.rc1
@@ -382,7 +382,24 @@
   xFUSER=`busybox fuser -m "$MOUNT_POINT" 2>/dev/null`
-  [ "$xFUSER" ] && busybox fuser -k -m "$MOUNT_POINT"
+# 1bit engine#3361: never fuser-kill rc.shutdown or its caller
+  if [ "$xFUSER" ]; then
+    STRAYSHID=`ps -A 2>/dev/null | grep " -sh$" | head -n 1 | sed -e "s/^ *//" | cut -f 1 -d " "`
+    ...
+  fi
(a second run is unchanged; busybox ash -n ok; grep -c of the old line is 0 and of the new mark is 1)

Rows

  • rc_shutdown_stray (new): registered in cmake/tests-rc-shutdown.cmake, runs 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).
  • shutdown_watch (existing): run; the only red row is 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

$ scripts/pre-pr-checks.sh --tree-only --base origin/main
pre-pr-checks: all 16 check(s) green, 2 skipped, 0 could not be told, 2 open-PR row(s) not run (--tree-only)

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

  1. The hook refuses a base whose rc.shutdown lacks the anchor line - a woof-CE change now fails the image build (cut.sh/container-build.sh treat exit 1 as a build failure) instead of silently shipping the bug again. Same policy the hook already had for its banner line.
  2. The console-shell exclusion deviates from woof-CE's own parse (sed "^ *" instead of "s%^ %%g"), because the appliance's padded ps rows make the upstream idiom read an empty pid; measured both ways on strixhalo.
  3. The test models fuser and ps with stubs and a padded-row width of 7 columns (the board's 7-digit pid width); the busybox-ash arm depends on the function-shim trick above.

Refs #3361

…- 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]>
@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 24, 2026 08:22
@bong-water-water-bong
bong-water-water-bong merged commit 7a1bab6 into main Nov 24, 2026
10 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/3361-stray-unmount-fuser branch November 24, 2026 08:24
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3361 - Partially compliant

Compliant requirements:

  • Fix the issue where rc.shutdown's stray-unmount loop kills rc.shutdown and its caller, causing reboot stalls
  • Ensure that the console shell is not killed by the fuser -k command
  • Make the fix idempotent and robust against changes in woof-CE's rc.shutdown
  • Add tests to verify the fix works correctly
  • Update documentation to reflect the change

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential PID exclusion logic flaw

The logic for excluding PIDs in the new fuser kill loop may not be robust. Specifically, the check case "$ONESTRAY" in $$|$PPID|$STRAYSHID) continue ;; esac might not correctly handle all cases where the console shell PID is not properly identified or when the PID list includes non-numeric entries. This could lead to unintended process termination.

'      case "$ONESTRAY" in $$|$PPID|$STRAYSHID) continue ;; esac' \
Console shell PID detection reliability

The method for detecting the console shell PID using ps -A 2>/dev/null | grep " -sh$" | head -n 1 | sed -e "s/^ *//" relies on the specific format of ps output. If the ps output format changes or if there are multiple processes matching the pattern, the wrong PID could be selected, potentially leading to the wrong process being excluded from the kill list.

'    STRAYSHID=`ps -A 2>/dev/null | grep " -sh$" | head -n 1 | sed -e "s/^ *//" | cut -f 1 -d " "`' \
'    [ "$STRAYSHID" ] || STRAYSHID=-1' \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant