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
@@ -68,7 +68,22 @@ if [ "${1-}" = --monitor ]; then
|
||||
# Acknowledge the private session before exec, so even an immediate monitor
|
||||
# crash leaves its ownership recorded. No worker can precede this handshake.
|
||||
trap 'exit 143' INT TERM
|
||||
printf '%s\n' "$$" > "$config_dir/monitor-ready"
|
||||
ack_temp=
|
||||
trap '[ -z "$ack_temp" ] || rm -f "$ack_temp"' EXIT
|
||||
ack_publish() {
|
||||
# Private same-UID directory: no untrusted writer can race the absent
|
||||
# destination check. Rename exposes complete bytes with a single link.
|
||||
[ -d "$config_dir" ] && [ ! -L "$config_dir" ] &&
|
||||
[ "$(stat -c '%u:%a' "$config_dir")" = "$(id -u):700" ] || return 1
|
||||
umask 077
|
||||
ack_temp=$(mktemp "$config_dir/.monitor-ready.XXXXXX") || return 1
|
||||
printf '%s\n' "$$" > "$ack_temp" || return 1
|
||||
[ ! -e "$config_dir/monitor-ready" ] && [ ! -L "$config_dir/monitor-ready" ] || return 1
|
||||
mv -T "$ack_temp" "$config_dir/monitor-ready" || return 1
|
||||
ack_temp=
|
||||
}
|
||||
ack_publish || { echo 'controller-startup: wrapper=ack_publish_failed' >&2; exit 78; }
|
||||
trap - EXIT
|
||||
echo 'controller-startup: wrapper=exec_pending' >&2
|
||||
exec "$@"
|
||||
elif [ "${1-}" = --watchdog ]; then
|
||||
|
||||
Reference in new issue
Block a user