Repository navigation
fix(session,script_driver): gate die_by_signal and tail exec replacement on process ownership (Refs #4211) - #4246
Merged
Conversation
…ent on process ownership (Refs #4211)
Member
Author
Member
Author
|
CAPTAIN-VERIFY(devin-mac 运行时复验):达合入门,队长合入。两枚新钉实跑绿——集成钉即嵌入宿主端到端形:SIGTERM 注入后宿主存活、status=143;fail-first 成立(中和双门→测试进程被 SIGTERM 自杀、还原复绿)。issue2346 首跑 9/11 后连跑 3 次 11/11,定谳时序抖动非回归;session_api 唯一红为先存的 macOS /private 路径规范形断言,非本 PR 账。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #4211 (item 4: isolate library-crate
die_by_signal/std::process::exitfrom embeddedSessionhosts).GNU C Reference & Embedding Contract
third_party/bash/sig.c:649-667(kill_shell): a standalone shell process dies by restoringSIG_DFLand re-raising the terminating signal sowaitpidreports signal death.rubash, standalone CLI invocations (src/main.rs) opt into process-level ownership viabuiltins::exec::enable_process_replacement(). Embedded library hosts (Sessioninsideniubash, editors, test harnesses) never opt in (src/builtins/exec.rs:93-111), and fork-copy executors (!owns_process_image) share a host process that must survive them.Root Cause
FinishPass::run_stream_end_duties(src/script_driver.rs:9501-9504) unconditionally calleddie_by_signal(sig)(libc::raise(sig)+std::process::exit(128 + sig)) whenevertermsig_deathwasSome(sig). BecauseSession::close/Session::close_with_report/Session::begin_finishall runFinishPass, an embeddedSessionfinishing with a pendingtermsig_deathterminated the entire host process instead of returning128 + sig.Executor::exec_replace_tail_ready(src/executor/external_inner.rs:2839) relied only indirectly on the-cfinal-frame stamp rather than explicitly enforcingprocess_replacement_enabled() && self.owns_process_imagebeforeCommand::exec/ fallbackstd::process::exit.Summary of Changes
src/script_driver.rs:die_by_signal(sig)inFinishPass::run_stream_end_dutiesoncrate::builtins::exec::process_replacement_enabled() && self.executor.owns_process_image().Sessionor fork-copy executor), setsself.resolved_status = 128 + sigand returns normally so the host observes128 + sigwithout process termination.finish_pass_process_ownership_tests::embedded_finish_reports_termsig_status_without_process_death.src/executor/public_accessors.rs:pub(crate) fn owns_process_image(&self) -> bool.src/executor/external_inner.rs:if !crate::builtins::exec::process_replacement_enabled() || !self.owns_process_image { return false; }guard at the entry ofexec_replace_tail_ready.tests/session_api.rs:#[cfg(unix)]regression testembedded_session_termsig_close_does_not_kill_host_processinside existingtests/session_api.rs(no new top-leveltests/issue*.rsbinary per#4210): re-executes the test binary as a child, injectsSIGTERMinto an embeddedSession, verifies theEXITtrap runs,close_with_report().status == 143, and the host process survives cleanly.What this PR deletes
die_by_signal(sig)call from embedded/non-process-ownerFinishPassruns.Verification
RUSTFLAGS="-D warnings" cargo check --lib --locked— passedcargo test --test session_api— 21/21 passed (includingembedded_session_termsig_close_does_not_kill_host_process)cargo test --lib script_driver— 21/21 passedcargo test --test issue2346_termsig_death_regressions— 11/11 passed (standalone CLIkill_shellsignal death preserved)RUSTFLAGS="-D warnings" cargo check --lib --locked— passedcargo test --lib script_driver— 20/20 passedscripts/check-api-ledger.py,scripts/check-marker-literals.py, and pre-commitscripts/check-rustfmt.pyall passed.