Compare commits

..
Author SHA1 Message Date
NoahandClaude Opus 5.5 07db1b9ec0 qemu: rig init honours reboot, poweroff and halt
ci / test (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / mcdc (push) Successful in 15s
ci / patches-apply (push) Successful in 22s
ci / qemu-tools (push) Successful in 46s
ci / qemu-tools (pull_request) Successful in 42s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 37s
ci / badges (push) Skipped
ci / test (pull_request) Successful in 13s
ci / mcdc (pull_request) Successful in 11s
ci / bench (pull_request) Successful in 5s
ci / patches-apply (pull_request) Successful in 16s
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
The stage-2 init is a busybox sh script running as PID 1. Busybox reboot,
poweroff and halt only signal PID 1 (TERM, USR2, USR1), and the kernel
drops a signal PID 1 has no handler for, so a plain reboot did nothing on
the rig while a panel's busybox init honours it. Settings > System >
Reboot hit exactly that (flare-edge#96).

warden_trap_power_signals performs the -f action after a sync, and
warden_idle_forever idles with sleep & wait so the trap runs at once
instead of after an hour-long foreground sleep.

Test: qemu/tests/init-power-signals-test.sh runs the real helpers in sh
with stub commands and sends each signal; it fails without the traps and
with a foreground sleep, and cannot hang on failure.

Fixes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:17:07 -06:00
noah eb0691d84f Merge pull request 'Clear the shellcheck findings that would fail qemu-tools' (#3) from sdk-shellcheck into flare-edge-next
ci / kernel-build (push) Skipped
ci / test (push) Successful in 17s
ci / mcdc (push) Successful in 18s
ci / bench (push) Successful in 8s
ci / patches-apply (push) Successful in 16s
ci / prune-artifacts (push) Skipped
ci / qemu-tools (push) Successful in 39s
ci / quality (push) Successful in 26s
ci / badges (push) Skipped
2026-09-28 03:30:57 -06:00
4 changed files with 73 additions and 2 deletions
+2
View File
@@ -148,6 +148,8 @@ jobs:
# on the debug channel. All offline (a stub qemu-system-arm on
# PATH), so it runs on every push/PR, not only a real boot.
run: bash qemu/tests/run-sh-args-test.sh
- name: rig init honours reboot/poweroff/halt (#5)
run: bash qemu/tests/init-power-signals-test.sh
- name: mkimage.sh SEED_DIR regression test
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
# otherwise; this builds the same unprivileged mkfs.ext4 image and
+21
View File
@@ -41,3 +41,24 @@ warden_slot() {
esac
echo "$slot"
}
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
# handler for. A panel's busybox init handles them; without this the rig
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
# the kernel still prints its orderly "reboot: Restarting system" line.
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
warden_trap_power_signals() {
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
}
# Idle forever in a way a trapped signal interrupts at once: a foreground
# `sleep` would hold the trap until it returned, up to an hour later.
warden_idle_forever() {
while :; do
sleep 3600 &
wait $!
done
}
+4 -2
View File
@@ -239,5 +239,7 @@ if grep -qw warden.shell /proc/cmdline; then
poweroff -f
fi
# Hold: daemons run, console idles, scenarios drive the VM from outside.
while :; do sleep 3600; done
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
warden_trap_power_signals
warden_idle_forever
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
# commands, idles it the way /sbin/init does, sends each signal and requires
# the matching action within two seconds.
set -uo pipefail
# Job control: each case's shell leads its own process group, so cleanup can
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
# script's output pipe open for an hour when a case fails.
set -m
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d)" || exit 1
trap 'rm -rf "$WORK"' EXIT
FAIL=0
run_case() { # run_case <signal> <expected marker> <label>
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
: > "$out"
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
"$SH" -c ". '$LIB'; warden_trap_power_signals; warden_idle_forever" &
local pid=$!
sleep 0.5
kill -"$sig" "$pid"
local n=0
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
sleep 0.1; n=$((n + 1))
done
if grep -qx "$want" "$out"; then
echo "[PASS] $label"
else
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
fi
kill -KILL -- "-$pid" 2>/dev/null
wait "$pid" 2>/dev/null
}
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
exit "$FAIL"