Skip to content

kill: refuse to kill/stop the session you're currently inside (mirrors attach's self-check) - #51

Open
FpTargeT wants to merge 1 commit into
mobydeck:mainfrom
FpTargeT:fix-kill-self-check
Open

kill: refuse to kill/stop the session you're currently inside (mirrors attach's self-check)#51
FpTargeT wants to merge 1 commit into
mobydeck:mainfrom
FpTargeT:fix-kill-self-check

Conversation

@FpTargeT

Copy link
Copy Markdown

Problem

`attach_main` already refuses to attach to a session that's in the caller's own ancestry chain (`SESSION_ENVVAR`), printing a clear message: `cannot attach to session '%s' from within itself`.

`kill_main` has no equivalent check. Running `atch kill ` (or `atch kill -f`) from inside the session you're trying to kill just races the SIGTERM/SIGKILL against your own shell's exit, with no explanation — confusing, especially for plain `kill` (no `-f`), which then waits out the full 5-second grace period before reporting.

Fix

  • Extracted the existing ancestry-chain scan from `attach_main` into a shared `session_in_ancestry()` helper (no behavior change for `attach`).
  • Added the same check to the top of `kill_main`, before it sends any signal, with a `kill`-specific message.
  • Added 3 new integration test scenarios (6 assertions) covering: self-kill without `-f`, self-kill with `-f`, and a control case confirming a non-ancestor session's kill is unaffected.

Testing

Full suite run locally: 235/235 passing (229 pre-existing + 6 new), 0 regressions. Built clean with `make`, no new warnings.

attach_main already refuses to attach to a session in the caller's own
ancestry chain (SESSION_ENVVAR), with a clear message. kill_main had no
equivalent check, so running `atch kill <own-session>` (or `kill -f`)
from inside that session just raced the signal against the caller's own
exit, with no explanation -- confusing especially for plain `kill`,
which then waits out the full 5-second grace period before reporting.

Extracted the existing ancestry-chain scan from attach_main into a
shared session_in_ancestry() helper (no behavior change for attach),
and added the same check to the top of kill_main with a kill-specific
message.

Added 3 new integration test scenarios (6 assertions) covering:
self-kill without -f, self-kill with -f, and a control case confirming
a non-ancestor session's kill is unaffected.

Full suite: 235/235 passing (229 pre-existing + 6 new), 0 regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant