Repository navigation
fix: kill 杀不掉后台 shell 子进程 + 管道写端无 SIGPIPE (#737) - #790
Merged
Merged
Conversation
…e SIGPIPE on unix
Contributor
|
欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。 |
This was referenced Oct 18, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
kill %1 followed by jobs/wait printed '[1]+ Exit 143 while true; do true; done' where GNU bash 5.3.0 prints nothing: a non-interactive reader suppresses the completion notice of a job the kill builtin itself terminated (jobs.c notify_of_job_status, the DONT_REPORT_SIGINT/SIGPIPE/SIGTERM + trapped arm - nothing printed, the dead job is cleaned up), and #790 (rubash#737) had dropped the jobspec-kill table cleanup to keep wait resolving the signal status. Restore the cleanup with the status-preserving removal: stash the signal status, close the coproc endpoints, drop the entry via remove_job_by_pid_preserve_status. kill %1; jobs lists nothing, no notice fires at the reap boundary, and a pid-shaped wait still resolves 143 through completed_statuses (#737's contract). The signal set follows the DONT_REPORT arm (SIGINT/SIGPIPE/SIGTERM or trapped, the same set report_pending_signal_notices already implements): kill -9 %1 keeps the entry so the async reap still announces Killed (GNU-verified), and pid operands are untouched for the #737 wrapper-death flow. Differential pins (part_036): test_kill_jobspec_leaves_no_completion_ notice and test_kill_pid_operand_then_wait_reports_signal_status, byte-verified against the WSL GNU 5.3.0(1)-release oracle.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
kill %1 followed by jobs/wait printed '[1]+ Exit 143 while true; do true; done' where GNU bash 5.3.0 prints nothing: a non-interactive reader suppresses the completion notice of a job the kill builtin itself terminated (jobs.c notify_of_job_status, the DONT_REPORT_SIGINT/SIGPIPE/SIGTERM + trapped arm - nothing printed, the dead job is cleaned up), and #790 (rubash#737) had dropped the jobspec-kill table cleanup to keep wait resolving the signal status. Restore the cleanup with the status-preserving removal: stash the signal status, close the coproc endpoints, drop the entry via remove_job_by_pid_preserve_status. kill %1; jobs lists nothing, no notice fires at the reap boundary, and a pid-shaped wait still resolves 143 through completed_statuses (#737's contract). The signal set follows the DONT_REPORT arm (SIGINT/SIGPIPE/SIGTERM or trapped, the same set report_pending_signal_notices already implements): kill -9 %1 keeps the entry so the async reap still announces Killed (GNU-verified), and pid operands are untouched for the #737 wrapper-death flow. Differential pins (part_036): test_kill_jobspec_leaves_no_completion_ notice and test_kill_pid_operand_then_wait_reports_signal_status, byte-verified against the WSL GNU 5.3.0(1)-release oracle.
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.
Closes #737
问题 1:kill 杀不掉后台任务
cmd &启动的后台任务,kill %1杀不掉——因为&实际 spawn 的是一个 wrapper 进程,kill 只杀死了 wrapper,真正的 shell 子进程还在跑。修复
wrapper 的 pre_exec 里用
prctl(PR_SET_PDEATHSIG, SIGKILL)(带 race 检查),父进程死后子进程自动被 SIGKILL;并通过环境变量__RUBASH_BACKGROUND_WRAPPER=1标记 wrapper 身份。KILL/TERM/INT/HUP 四种信号验证均为 DIED。问题 2:管道写端无 SIGPIPE
execute_shell_writer_pipeline在 Unix 上是个空 stub,根本没启用。修复
把 Windows 实现的
#[cfg(windows)]放宽为#[cfg(any(windows, unix))],并加 Unix 版 stdio 转换分支。验证PIPESTATUS=141与 GNU 一致。顺带
修了
kill %N立刻丢 job 表项的问题(现在与 GNU 一致,job 保留到被 wait/reap)。验证
issue345 测试 5/5 通过;
cargo test --lib608 通过(1 个失败是 root 环境下属主检查的 pre-existing 问题)。未做
裸 coproc 的 parser 问题(与本 issue 无关,另案处理)。