38 lines
1.1 KiB
Bash
38 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Sourced by runners. Only signal children whose PIDs this runner still owns.
|
|
# Clear each PID immediately after wait, so EXIT cannot signal a reused PID.
|
|
child_pid=""
|
|
redactor_pid=""
|
|
sampler_pid=""
|
|
proxy_pid=""
|
|
|
|
cleanup_playable_processes() {
|
|
local status=$? pid round alive
|
|
trap - EXIT
|
|
trap '' HUP INT TERM
|
|
for pid in "$child_pid" "$redactor_pid" "$sampler_pid" "$proxy_pid"; do
|
|
if [ -n "$pid" ]; then kill -TERM "$pid" 2>/dev/null || true; fi
|
|
done
|
|
for ((round=0; round<${process_cleanup_grace_seconds:-10}; round++)); do
|
|
alive=0
|
|
for pid in "$child_pid" "$redactor_pid" "$sampler_pid" "$proxy_pid"; do
|
|
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then alive=1; fi
|
|
done
|
|
[ "$alive" -eq 1 ] || break
|
|
sleep 1
|
|
done
|
|
for pid in "$child_pid" "$redactor_pid" "$sampler_pid" "$proxy_pid"; do
|
|
if [ -n "$pid" ]; then
|
|
kill -KILL "$pid" 2>/dev/null || true
|
|
wait "$pid" 2>/dev/null || true
|
|
fi
|
|
done
|
|
if [ -n "${fifo:-}" ] && [ -p "$fifo" ]; then rm -f "$fifo"; fi
|
|
return "$status"
|
|
}
|
|
|
|
trap cleanup_playable_processes EXIT
|
|
trap 'exit 129' HUP
|
|
trap 'exit 130' INT
|
|
trap 'exit 143' TERM
|