Skip to content

os/v3/puppy: rc.shutdown names each step in the kernel log, so a stalled reboot shows where (engine#3287) - #3330

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/shutdown-watch
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/shutdown-watch

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Part of #3287, item 1: make the frozen reboot observable.

Why: the plain reboot of the installed c35 on 22 Nov (orchestrator GO; evidence in the #3287 comment) sat 3 min 24 s in rc.shutdown. The old boot has two shutdown markers, at 19:57:55Z and 20:01:19Z. Nothing reached the kernel log after eno1: Link is Down, and pstore held nothing. Nothing said which step it was in.

Change:

  • embed/usr/local/bin/1bit-shutdown-watch <pid> follows rc.shutdown's process tree once a second, down to the command it is waiting on. It writes one kernel-log line whenever that changes (1bit-shutdown: step <pid> <command line>). A step still running after 10, 20, 40 s… gets its state, wchan and kernel stack.
    • For the rest of the shutdown it sets printk_devkmsg=on (userspace kmsg is otherwise rate-limited) and console log level 7 (the appliance boots at 1).
    • Why the kernel log: a file on /data would hold open the file system rc.shutdown unmounts. The kernel log reaches the screen, the serial console, the next shutdown's 1bit-logs snap (which is how the 22 Nov stall was read) and the efi-pstore record (os/v3/puppy: every reboot leaves its kernel log tail in EFI pstore, and the next boot files it (engine#3287) #3306).
    • One printf per line, so one record each. busybox ash's set -x writes a trace line in pieces; I measured that on the box.
    • No subshell in the once-a-second walk: rc.shutdown's killzombies answers a transient zombie by killing its parent.
  • hook-rc-shutdown.sh <rc.shutdown> adds one backgrounded line after woof-CE's Executing /etc/rc.d/rc.shutdown... banner. It is idempotent and refuses a file without the banner.
  • README row; tests/shutdown_watch_test.sh is registered as ctest shutdown_watch.

Measured:

  • tests/shutdown_watch_test.sh: 14/14 under dash with env -i (as CI runs it, unprivileged, no hardware), and 14/14 under busybox ash. It runs ~5 s on a real process tree, with a file standing in for the kernel log. It does not skip; there is no skip path.
  • On the box (c35, busybox ash, as root, real /dev/kmsg; ONEBIT_KMSG set so the live printk settings were left alone): dmesg shows 1bit-shutdown: still in 426826 sleep 3 after 2 s, state S, wchan hrtimer_nanosleep, then the stack lines ([<0>] hrtimer_nanosleep+0x8a/0x100 …), then rc.shutdown 426825 finished. Each is one record.
  • The hook on the real v2026.47 base rc.shutdown: two lines added after line 54, and a second run changes nothing. busybox ash -n passes on the hooked file.
  • bash scripts/pre-pr-checks.sh --base origin/main: 17 green, 3 skipped.

Not run: a real shutdown with the hook. That needs an image with it plus a reboot of the appliance, which is the next GO.

🤖 Generated with Claude Code

…led reboot shows where (engine#3287)

The 22 Nov plain reboot of the installed c35 sat 3 min 24 s in rc.shutdown (two shutdown markers, 19:57:55Z and
20:01:19Z) with nothing in the kernel log after eno1: Link is Down, and no pstore record. Nothing said which step.

1bit-shutdown-watch <pid> (embed, /usr/local/bin) follows rc.shutdown's process tree once a second and writes one
kernel-log line per step, plus state, wchan and kernel stack for a step still running after 10/20/40 s; it raises the
console log level to 7 and lifts the /dev/kmsg rate limit for the rest of the shutdown. hook-rc-shutdown.sh starts it
from rc.shutdown right after the Executing banner; container-build.sh runs the hook on the skeleton (and refuses a
packed rc.shutdown without it), cut.sh BASE mode on the base's copy. tests/shutdown_watch_test.sh (14 checks) runs the
watcher on a real process tree with a file for the kernel log, and the hook on rc.shutdown's banner lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3287 - Partially compliant

Compliant requirements:

  • The PR introduces 1bit-shutdown-watch and hook-rc-shutdown.sh to monitor shutdown steps
  • The scripts are integrated into container-build.sh and cut.sh as required
  • A test script shutdown_watch_test.sh is added to verify the functionality

Non-compliant requirements:

  • The PR does not address the issue of the data partition not being grown on first boot
  • The PR does not address the issue of the cut not using the freshly rolled payload
  • The PR does not address the issue of the pre-write probe not being able to stop the write
  • The PR does not address the issue of keeping the shipped image

Requires further human verification:

  • The effectiveness of the shutdown monitoring in real-world scenarios needs to be verified
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Process Tree Walking Issue

The 1bit-shutdown-watch script walks the process tree by reading /proc/[0-9]*/stat and checking parent PIDs. This approach might miss processes that are created or destroyed between reads, potentially leading to incorrect process tracking. While the script uses built-ins to minimize subshells, there's a risk of race conditions in a high-concurrency environment.

child_of() {
    kid=
    for st in "$P"/[0-9]*/stat; do
        [ -r "$st" ] || continue
        IFS= read -r line < "$st" 2> /dev/null || continue
        rest=${line##*) }                 # "S ppid ..." (comm may hold spaces and parentheses)
        pp=${rest#* }; pp=${pp%% *}
        [ "$pp" = "$1" ] || continue
        c=${st%/stat}; c=${c##*/}
        if [ -z "$kid" ] || [ "$c" -gt "$kid" ]; then kid=$c; fi
    done
}
Idempotency Check

The hook-rc-shutdown.sh script checks for the presence of the hook marker before adding it. However, it only checks for the marker's existence and does not verify that the hook is correctly placed after the banner line. This could lead to a situation where the hook is added multiple times or in an incorrect location.

grep -qF "$mark" "$f" && exit 0
grep -q '^echo "Executing /etc/rc.d/rc.shutdown\.\.\."' "$f" || {
    echo "hook-rc-shutdown.sh: REFUSED: $f has no 'Executing /etc/rc.d/rc.shutdown...' line to hook after" >&2; exit 1; }
sed -i "/^echo \"Executing \/etc\/rc.d\/rc.shutdown\.\.\.\"/a\\
$mark\\
[ -x /usr/local/bin/1bit-shutdown-watch ] \&\& /usr/local/bin/1bit-shutdown-watch \$\$ < /dev/null > /dev/null 2>\&1 \&" "$f"
[ "$(grep -c '1bit-shutdown-watch \$\$' "$f")" = 1 ] || {
    echo "hook-rc-shutdown.sh: REFUSED: the hook line did not land exactly once in $f" >&2; exit 1; }
exit 0

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