fix: publish controller startup acknowledgements atomically
Publish a complete PID acknowledgement by private temporary file and same-directory rename. Preserve unknown acknowledgement artifacts and remove only retained owned stale state. Keep malformed acknowledgement failures closed. Cover deterministic publication barriers, shared apply/monitor/qualify launch, foreign artifacts, owned replacement, and private-directory checks. This does not establish hostile root or same-UID writer no-clobber guarantees; the private mode-700 directory is the trust boundary. Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
ade3b89137
commit
36aace02da
3 files changed
+139
-27
No files matched your search
@@ -337,7 +337,20 @@ start_dns() {
|
||||
done
|
||||
}
|
||||
launch_controller() {
|
||||
rm -f "$config_dir/monitor-ready"
|
||||
# Only an ACK retained from our previous launch is owned stale state.
|
||||
# Unknown files (including dangling links) are evidence, not debris.
|
||||
if [ -e "$config_dir/monitor-ready" ] || [ -L "$config_dir/monitor-ready" ]; then
|
||||
if [ -z "${monitor_ready_identity-}" ] || [ -L "$config_dir/monitor-ready" ] ||
|
||||
[ ! -f "$config_dir/monitor-ready" ] ||
|
||||
[ "$(stat -c '%d:%i:%u:%a:%h' "$config_dir/monitor-ready")" != "$monitor_ready_identity" ] ||
|
||||
! { read -r stale_pid < "$config_dir/monitor-ready"; } 2>/dev/null ||
|
||||
[ "$stale_pid" != "${monitor_ready_pid-}" ]; then
|
||||
echo 'controller-startup: launch=ack_conflict' >&2
|
||||
return 78
|
||||
fi
|
||||
rm -f "$config_dir/monitor-ready" || return 78
|
||||
fi
|
||||
monitor_ready_identity=
|
||||
setsid /bin/sh /opt/managed-target-supervision.sh --monitor "$config_dir" /usr/local/bin/zapret-autotune "$@" 8<&- 9<&- &
|
||||
monitor_pid=$!
|
||||
monitor_ack_deadline=$(($(date +%s) + 5))
|
||||
@@ -353,6 +366,8 @@ launch_controller() {
|
||||
fi
|
||||
done
|
||||
capture_monitor_session || return 78
|
||||
monitor_ready_identity=$(stat -c '%d:%i:%u:%a:%h' "$config_dir/monitor-ready") || return 78
|
||||
monitor_ready_pid=$monitor_pid
|
||||
if proc_identity "$monitor_pid" && [ "$proc_sid" != "$monitor_sid" ]; then
|
||||
echo 'controller-startup: launch=session_mismatch' >&2
|
||||
monitor_sid=
|
||||
@@ -416,7 +431,6 @@ fi
|
||||
# fork a monitor we already need to cancel: an early TERM can race interpreter
|
||||
# startup before its cancellation handler exists. Clean this cycle directly.
|
||||
{ dns_alive && kill -0 "$server_pid" 2>/dev/null && kill -0 "$local_pid" 2>/dev/null; } || return 75
|
||||
rm -f "$config_dir/monitor-ready"
|
||||
if [ "$qualification_mode" -eq 1 ]; then
|
||||
qualification_attempted=1
|
||||
set -- qualify --config "$ZAPRET_AUTOTUNE_QUALIFY_CONFIG" --strategies "$ZAPRET_AUTOTUNE_STRATEGY_CONFIG" --isolated
|
||||
|
||||
Reference in new issue
Block a user