Skip to content

Commit c30dea7

Browse files
committed
fix(rootfs/qemu-static): killswitch builder anchors emulation lock; native builder probes EX-NB before disabling qemu-arm
K-builder (NATIVE_ARMHF_ON_ARM64=no) now takes a SH-lock on /proc/sys/fs/binfmt_misc/qemu-arm for its lifetime instead of returning immediately. N-builder (default) probes EX-NB on a fresh fd before acquiring its own SH; if probe fails AND qemu-arm is observably enabled (state==1), a K-builder holds the emulation anchor and switching to native mid-flight would corrupt their qemu-arm-static routing — refuse with exit_with_error. Symmetric closure of the K↔N race: - N→K: K sees qemu-arm=0 → fail-fast via the existing prepare_host guard (addressed in 9d8b848). - K→N: N sees EX-NB fail + state=1 → fail-fast with 'concurrent build with NATIVE_ARMHF_ON_ARM64=no holds emulation lock' (this commit). Verified end-to-end on Hetzner CAX21 (4-core Ampere Altra, Ubuntu 6.8): - N first, K second: K exits 8s with 'qemu-arm globally disabled by another concurrent build'. - K first, N second: N exits 12s with 'cannot enable native armhf: concurrent build with NATIVE_ARMHF_ON_ARM64=no holds emulation lock'. - Cleanup of both K (release SH) and N (last-out restore echo 1) leaves qemu-arm in 'enabled' state. Assisted-by: Claude:claude-opus-4.7
1 parent 9c415c3 commit c30dea7

2 files changed

Lines changed: 233 additions & 80 deletions

File tree

lib/functions/logging/traps.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ function add_cleanup_handler() {
140140
trap_manager_cleanup_handlers=("${callback}" "${trap_manager_cleanup_handlers[@]}")
141141
}
142142

143+
# Like add_cleanup_handler but appends to the tail of the list, so the
144+
# registered callback runs AFTER everything added with add_cleanup_handler
145+
# at the time run_cleanup_handlers fires. Use this when a handler needs to
146+
# observe a fully-torn-down state — e.g. it can't safely re-mutate a
147+
# kernel-global resource while subshells of the build are still alive and
148+
# may have inherited the resource's fd.
149+
function add_cleanup_handler_last() {
150+
if [[ $# -gt 1 ]]; then
151+
exit_with_error "add_cleanup_handler_last: too many params"
152+
fi
153+
local callback="$1"
154+
if [[ -z "${callback}" ]]; then
155+
exit_with_error "add_cleanup_handler_last: no callback specified"
156+
fi
157+
158+
display_alert "Add callback as last cleanup handler" "${callback}" "cleanup"
159+
trap_manager_cleanup_handlers+=("${callback}")
160+
}
161+
143162
function execute_and_remove_cleanup_handler() {
144163
local callback="$1"
145164
display_alert "Execute and remove cleanup handler" "${callback}" "cleanup"

0 commit comments

Comments
 (0)