fix: a signal during party host rolls back and stops

The rollback trap was armed on EXIT INT TERM HUP with a body that did
not exit. After a signal the shell ran the cleanup, then resumed
cmd_host and kept configuring the party dir it had just removed.
Keep the cleanup on EXIT and make the signal traps exit with the
conventional 128+n status.
This commit is contained in:
veg 2026-09-21 09:32:01 +00:00
parent 6c48777553
commit 851cef6941
2 changed files with 26 additions and 1 deletions

9
party
View file

@ -796,10 +796,17 @@ EOF
# mkdir race tear down the winner's directory and tmux server via # mkdir race tear down the winner's directory and tmux server via
# set -e + EXIT trap. Now the trap fires only on resources this # set -e + EXIT trap. Now the trap fires only on resources this
# process actually created. Disarmed once roster_write commits. # process actually created. Disarmed once roster_write commits.
#
# The cleanup hangs off EXIT alone; the signal traps only exit. A
# signal trap body that returns lets the shell resume where it was
# interrupted, which here means configuring a dir we just removed.
trap ' trap '
"$PARTY_TMUX" -S "$sock" kill-server 2>/dev/null || true "$PARTY_TMUX" -S "$sock" kill-server 2>/dev/null || true
rm -rf "$party_dir" rm -rf "$party_dir"
' EXIT INT TERM HUP ' EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
chgrp "$TMUX_PARTY_GROUP" "$party_dir" chgrp "$TMUX_PARTY_GROUP" "$party_dir"
chmod 0750 "$party_dir" chmod 0750 "$party_dir"

View file

@ -39,6 +39,9 @@ case "$*" in
*"new-session -d "*) *"new-session -d "*)
# cmd_host expects the socket file to exist for apply_party_perms_file. # cmd_host expects the socket file to exist for apply_party_perms_file.
[ -n "$sock" ] && : > "$sock" [ -n "$sock" ] && : > "$sock"
# Optional injection point for the signal test: TERM the calling
# party process while it waits on us, mid-setup.
[ -n "${SIGNAL_ON_NEWSESSION:-}" ] && kill -TERM "$PPID"
;; ;;
*"display-message -p "*) *"display-message -p "*)
# Caller is fishing for #{pid}; emit the sleeper's PID. # Caller is fishing for #{pid}; emit the sleeper's PID.
@ -557,6 +560,21 @@ STUB
[ ! -e "$party_dir" ] [ ! -e "$party_dir" ]
} }
@test "host interrupted by a signal rolls back and stops" {
# A signal trap body that does not exit lets the shell resume where
# it left off: cmd_host would clean up, then carry on configuring a
# party dir it just removed. The signal must end the run.
party_dir="$PARTY_SOCKET_DIR/party-$USER:sigterm.d"
SIGNAL_ON_NEWSESSION=1 run "$PARTY_BIN" host sigterm
[ "$status" -eq 143 ]
[ ! -e "$party_dir" ]
# Nothing but the rollback's kill-server follows new-session.
[ "$(sed -n '/new-session -d /,$p' "$TMUX_LOG" | sed 1d)" \
= "-S $party_dir/sock kill-server" ]
}
@test "host refuses leftover per-party dir without a roster" { @test "host refuses leftover per-party dir without a roster" {
# Simulate a prior incarnation that left a per-party dir behind with # Simulate a prior incarnation that left a per-party dir behind with
# no roster (the rollback trap couldn't fire — SIGKILL or panic). # no roster (the rollback trap couldn't fire — SIGKILL or panic).