ci: capture native recovery startup context before platform probe

This commit is contained in:
dh
2026-10-03 16:38:34 +02:00
parent 0a30a1ca5a
commit b40234d3b5
3 changed files with 99 additions and 13 deletions
+48 -9
View File
@@ -45,28 +45,59 @@ finish() {
run_command() {
local name="$1"
shift
local process timer sleeper exit_code
local process timer sleeper exit_code started observer=""
LAST_OUTPUT="/tmp/native-diagnostic-$name.out"
printf '\n[proof-command] %s:' "$name" >> "$PROOF_LOG"
printf ' %s' "$@" >> "$PROOF_LOG"
printf '\n' >> "$PROOF_LOG"
started=$SECONDS
"$@" > "$LAST_OUTPUT" 2>&1 &
process=$!
printf '[proof-start] %s child=%s shell=%s parent=%s seconds=%s\n' "$name" "$process" "$$" "$PPID" "$started" >> "$PROOF_LOG"
(
trap 'kill "$sleeper" 2>/dev/null || :; exit 0' TERM INT
sleep 45 &
sleeper=$!
wait "$sleeper"
printf '[proof-timeout] %s child=%s elapsed=%ss signal=TERM\n' "$name" "$process" "$((SECONDS - started))" >> "$PROOF_LOG"
kill -TERM "$process" 2>/dev/null || :
sleep 2
sleep 2 & sleeper=$!; wait "$sleeper"
kill -KILL "$process" 2>/dev/null || :
) &
timer=$!
if [[ "$name" = platform || "$name" = platform-warm ]]; then
# Observers never extend the independent 45-second command deadline.
(
local sample_pid="" sample_timer="" pause_pid="" pause sample_exit
trap 'kill -KILL "$sample_pid" 2>/dev/null || :; kill -TERM "$sample_timer" "$pause_pid" 2>/dev/null || :; exit 0' TERM INT
for pause in 10 15; do
sleep "$pause" & pause_pid=$!; wait "$pause_pid"
printf '[proof-process] %s child=%s elapsed=%ss fields=pid,ppid,stat,cpu-time,elapsed,cpu-percent,wchan,comm\n' "$name" "$process" "$((SECONDS - started))" >> "$PROOF_LOG"
/bin/ps -p "$process" -o pid=,ppid=,stat=,time=,etime=,pcpu=,wchan=,comm= >> "$PROOF_LOG" 2>&1 &
sample_pid=$!
(
local sample_sleeper=""
trap 'kill "$sample_sleeper" 2>/dev/null || :; exit 0' TERM INT
sleep 5 & sample_sleeper=$!; wait "$sample_sleeper"
kill -KILL "$sample_pid" 2>/dev/null || :
) & sample_timer=$!
wait "$sample_pid"; sample_exit=$?
kill -TERM "$sample_timer" 2>/dev/null || :; wait "$sample_timer" 2>/dev/null || :
printf '[proof-process-exit] %s %s\n' "$name" "$sample_exit" >> "$PROOF_LOG"
sample_pid=""; sample_timer=""; pause_pid=""
done
) & observer=$!
fi
wait "$process"
exit_code=$?
kill -TERM "$timer" 2>/dev/null || :
wait "$timer" 2>/dev/null || :
if [ -n "$observer" ]; then
kill -TERM "$observer" 2>/dev/null || :
wait "$observer" 2>/dev/null || :
fi
/usr/bin/tail -c 524288 "$LAST_OUTPUT" >> "$PROOF_LOG"
printf '\n[proof-duration] %s child=%s elapsed=%ss\n' "$name" "$process" "$((SECONDS - started))" >> "$PROOF_LOG"
printf '\n[proof-exit] %s\n' "$exit_code" >> "$PROOF_LOG"
LAST_EXIT="$exit_code"
local size
@@ -75,13 +106,7 @@ run_command() {
return 0
}
run_command platform /usr/bin/sw_vers
(( LAST_EXIT == 0 )) || finish false sw_vers_failed
run_command version /usr/bin/sw_vers -productVersion
(( LAST_EXIT == 0 )) || finish false product_version_failed
os_version=$(cat "$LAST_OUTPUT")
[[ "$os_version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]] || finish false product_version_invalid
(( ${os_version%%.*} >= 14 )) || finish false unsupported_macos_version
# Collect cheap native identity/context before the first framework-dependent probe.
run_command kernel /usr/bin/uname -a
(( LAST_EXIT == 0 )) || finish false uname_failed
run_command architecture /usr/bin/uname -m
@@ -94,14 +119,28 @@ run_command uid /usr/bin/id -u
uid=$(cat "$LAST_OUTPUT")
[ "$uid" = 0 ] || finish false recovery_account_not_root
run_command bootargs /usr/sbin/sysctl kern.bootargs
run_command cpu /usr/sbin/sysctl machdep.cpu.brand_string machdep.cpu.features machdep.cpu.leaf7_features
run_command parent /bin/ps -p "$$" -p "$PPID" -o pid=,ppid=,comm=
run_command processes /bin/ps -axo pid,ppid,comm
run_command platform /usr/bin/sw_vers
platform_exit="$LAST_EXIT"
run_command system /bin/launchctl print system
system_exit="$LAST_EXIT"
run_command arbitration /bin/launchctl print system/com.apple.diskarbitrationd
arbitration_exit="$LAST_EXIT"
run_command recovery /bin/launchctl print system/com.apple.recoveryosd
recovery_exit="$LAST_EXIT"
if (( platform_exit != 0 )); then
printf '[proof-retry] sw_vers once after native service context; same 45-second deadline\n' >> "$PROOF_LOG"
run_command platform-warm /usr/bin/sw_vers
platform_exit="$LAST_EXIT"
fi
(( platform_exit == 0 )) || finish false sw_vers_failed
run_command version /usr/bin/sw_vers -productVersion
(( LAST_EXIT == 0 )) || finish false product_version_failed
os_version=$(cat "$LAST_OUTPUT")
[[ "$os_version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]] || finish false product_version_invalid
(( ${os_version%%.*} >= 14 )) || finish false unsupported_macos_version
# Bound readiness independently of the host's 40-minute overall deadline.
readiness_start=$SECONDS