Observe owned diskutil stack and live StorageKit in Recovery

This commit is contained in:
dh
2026-10-04 17:35:06 +02:00
parent 9164fe451f
commit 81a3b9c7d2
3 changed files with 95 additions and 13 deletions
+32 -11
View File
@@ -142,10 +142,11 @@ read_native_system_version() {
}
# END native SystemVersion plist request helpers
# BEGIN disk IPC diagnostic
# Optional observations have their own child/timer ownership. Thread state/time
# targets only this probe's diskutil and does not request stack symbolication.
# Optional observations have their own child/timer ownership. Stack/thread
# observations target only this probe's live diskutil; none qualifies readiness.
observe_disk_query() {
local disk_process="$1" output="$2" observation_child="" observation_timer=""
local stack_output="$STATE_DIR/diskutil-stack.txt"
cancel_observation() {
trap '' TERM INT
if [ -n "$observation_child" ]; then
@@ -179,19 +180,38 @@ observe_disk_query() {
kill -TERM "$observation_timer" 2>/dev/null || :
wait "$observation_timer" 2>/dev/null || :
printf '[disk-observation-exit] %s status=%s elapsed=%ss\n' "$name" "$status" "$((SECONDS - started))" >> "$output"
OBSERVATION_EXIT="$status"
observation_child=""; observation_timer=""
}
observe_live_command() {
local name="$1"
shift
if ! kill -0 "$disk_process" 2>/dev/null; then
printf '[disk-observation-unavailable] %s: owned diskutil already exited\n' "$name" >> "$output"
elif [ ! -x "$1" ]; then
printf '[disk-observation-unavailable] %s: %s is unavailable\n' "$name" "$1" >> "$output"
else
observe_command "$name" "$@"
fi
}
trap cancel_observation TERM INT
printf '[disk-observation] owned-diskutil-child=%s parent-shell=%s\n' "$disk_process" "$$" >> "$output"
if [ -x /bin/ps ]; then
if kill -0 "$disk_process" 2>/dev/null; then
observe_command diskutil-threads /bin/ps -M -p "$disk_process"
else
printf '[disk-observation-unavailable] diskutil already exited before thread observation\n' >> "$output"
fi
observe_live_command diskutil-threads-before /bin/ps -M -p "$disk_process"
if [ ! -x /usr/bin/sample ]; then
printf '[disk-observation-unavailable] diskutil-stack: /usr/bin/sample is unavailable\n' >> "$output"
elif ! kill -0 "$disk_process" 2>/dev/null; then
printf '[disk-observation-unavailable] diskutil-stack: owned diskutil already exited\n' >> "$output"
elif [ -e "$stack_output" ] || [ -L "$stack_output" ]; then
printf '[disk-observation-unavailable] diskutil-stack: output already exists\n' >> "$output"
elif : > "$stack_output"; then
printf '[disk-stack-attempt] owned-diskutil-child=%s duration=1s interval=100ms limit=60s output=%s observation-only=true\n' "$disk_process" "$stack_output" >> "$output"
observe_command diskutil-stack /usr/bin/sample "$disk_process" 1 100 -mayDie -file "$stack_output"
printf '[disk-stack-result] status=%s observation-only=true; raw report is captured by the Linux host\n' "$OBSERVATION_EXIT" >> "$output"
else
printf '[disk-observation-unavailable] /bin/ps is unavailable\n' >> "$output"
printf '[disk-observation-unavailable] diskutil-stack: output cannot be created\n' >> "$output"
fi
observe_live_command storagekit-live /bin/launchctl print system/com.apple.storagekitd
observe_live_command diskutil-threads-after /bin/ps -M -p "$disk_process"
}
stop_disk_observation() {
@@ -226,7 +246,7 @@ run_command() {
# Isolate only the failed UID gate; every other watchdog remains unchanged.
[[ "$name" != uid ]] || command_limit=180
# BEGIN disk IPC diagnostic
if [[ "$name" == disks && "${attempt:-0}" == 1 ]]; then command_limit=120; fi
if [[ "$name" == disks && "${attempt:-0}" == 1 ]]; then command_limit=600; fi
# END disk IPC diagnostic
LAST_OUTPUT="/tmp/native-diagnostic-$name.out"
printf '\n[proof-command] %s:' "$name" >&3
@@ -314,8 +334,9 @@ os_version="$SCALAR"
flush_outputs || finish false diagnostic_log_budget_exceeded
# BEGIN disk IPC diagnostic
printf '[disk-diagnostic-runtime] bash=%s stack-observation-only=true\n' "$BASH_VERSION" >&3
run_command arbitration_before /bin/launchctl print system/com.apple.diskarbitrationd
run_command management_before /bin/launchctl print system/com.apple.diskmanagementd
run_command management_before /bin/launchctl print system/com.apple.storagekitd
run_command media_before /usr/sbin/ioreg -r -c IOMedia -l -w 0
flush_outputs || finish false diagnostic_log_budget_exceeded