Repository navigation
fix(jobs): only a WIFSIGNALED status may use the kill delivery record (Refs #3802) - #3841
Merged
Merged
Conversation
… (Refs #3802) #3805 made the jobs table name the signal this shell's own kill delivered, decoding the Windows `TerminateProcess (128+signal)` exit code against a per-pid delivery record. The decode was unconditional: `take_delivered_signal(pid)` ignored the reaped status, so on unix a job that ignored or trapped SIGTERM and then exited on its own was rendered from the record instead of its wait status -- `trap "" TERM; exit 5` printed `Terminated` where GNU prints `Exit 5`, and `trap "exit 143" TERM` printed `Terminated` where GNU prints `Exit 143`. GNU decides the wording from the wait status alone: jobs.c:1969-2015 printable_job_status() calls j_strsignal(WTERMSIG(p->status)) only in the WIFSIGNALED arm, and the WIFEXITED arm always renders `Exit %d` (jobs.c wait_for reaps the status; kill_pid, jobs.c:3988-4007, is pure delivery and never proof of death). A code equal to 128+signal is not that proof: an `exit 143` is WIFEXITED. Owner split: - unix: the kernel wait status is authoritative (exit_status_signal), so the delivery record is only consumed, never applied (JobTable::discard_delivered_signal); - Windows: no WIFSIGNALED exists, so the record supplies the signal only when the reaped code is exactly 128+signal (take_delivered_signal(pid, status)). Oracle: WSL GNU bash 5.3.20 script files vs the fixed Linux binary, 5 shapes x {jobs-then-wait, wait-then-jobs} -- byte-identical except the pre-existing Killed notice path (shell path/pid, #3803 face): a. trap "" TERM; exit 5 -> [1]+ Exit 5 rc=5 b. trap "exit 143" TERM -> [1]+ Exit 143 rc=143 c. kill -9 (real SIGKILL) -> [1]+ Killed rc=137 d. kill -TERM default -> [1]+ Terminated rc=143 e. plain exit 7 -> [1]+ Exit 7 rc=7 Fail-first on master: a/b print Terminated. Pins: tests/issue3802_delivered_signal_guard.rs 5/5 (trapped shapes `#[cfg(unix)]`; Windows now has no in-child signal disposition), plus the #3805 pin 4/4 on Windows and Linux. Neighbouring jobs/wait stems unchanged (issue2340's two reds are identical on master).
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 #3802(issue 保持 OPEN)
#3805 让 jobs 表用「本 shell 自己 kill 投递的信号」给 Windows 的
TerminateProcess(128+signal)退出码命名(Killed/Terminated),但 decode 没有校验 reap 出来的 wait status:take_delivered_signal(pid)只看 pid。于是在 unix 上,一个忽略/捕获了 SIGTERM 之后自己退出的 job 被按投递记录渲染成信号死亡——trap "" TERM; exit 5打印Terminated(GNU 是Exit 5),trap "exit 143" TERM打印Terminated(GNU 是Exit 143)。这是 #3805 合入后引入的 master 回归。GNU 锚点(再核)
third_party/bash/jobs.c:1969-2015 printable_job_status():只有WIFSIGNALED分支走j_strsignal (WTERMSIG (p->status));WIFEXITED分支一律Exit %d(es == 0才是Done)。所以「退出码等于 128+signal」不是 WIFSIGNALED 的证据:exit 143是 WIFEXITED,GNU 打Exit 143。jobs.c:3988-4007 kill_pid:纯投递;投递 ≠ 死亡。jobs.cwait_for/waitchld:死亡由 wait status 报告,jobs 表只读它。修法(owner 分层,不在渲染层)
src/jobs/table.rstake_delivered_signal(pid, status):只有status == 128 + signal才返回信号;不匹配时消费记录并返回None(pid 复用不能借用旧投递)。discard_delivered_signal(pid):内核 wait status 权威的平台只消费、不应用。src/executor/job_builtins.rsExecutor::delivered_term_signal(pid, status):cfg(unix)下丢弃记录返回None(exit_status_signal已给出真 WIFSIGNALED/WTERMSIG,exit 143与 SIGTERM 死亡在 code 上不可区分,不能靠 code 猜);cfg(not(unix))下走带 status 门控的take_delivered_signal。apply_job_completion用它替代原来的无门控take_delivered_signal(pid)。渲染层(
render_background_jobs/printable_job_status移植)未改。GNU 5.3.20 矩阵(WSL 脚本文件;5 形 × jobs-then-wait / wait-then-jobs)
trap "" TERM; exit 5[1]+ Exit 5/ rc=5trap "exit 143" TERM(睡眠后自退出)[1]+ Exit 143/ rc=143kill -9[1]+ Killed/ rc=137kill -TERM(默认处置)[1]+ Terminated/ rc=143exit 7[1]+ Exit 7/ rc=710 个格逐字节比对,唯一差异是 c-wait 的死亡通知行(shell 路径 + pid,
#3803的既有措辞面,非本 PR)。fail-first:master 上 a/b 均为Terminated。Pin
tests/issue3802_delivered_signal_guard.rs(5 格):issue3802_ignored_term_then_exit_5_is_exit_5(#[cfg(unix)])issue3802_trapped_term_then_exit_143_is_exit_143(#[cfg(unix)])issue3802_real_kill9_still_renders_killedissue3802_plain_exit_7_is_exit_7issue3802_wait_then_jobs_has_no_stale_row结果:Windows 3 passed(2 个 unix 格按 cfg 跳过);Linux 5/5。既有
issue3802_jobs_table_killed_wording在两侧仍 4/4。邻接 stem:
issue1048_1256(5)、issue1494(2)、issue1604(1)、issue3803(5) 绿;issue2340_wait_job_retention的 2 格红与 master 逐格相同(既存/flake,非本 PR)。本 PR 删除了什么
无功能删除:只把一个无门控的 decode 换成带
WIFSIGNALED语义的分平台 owner(unix 只消费记录,Windows 才应用且需status == 128+signal),并新增 1 个测试文件。UNVERIFIED-BY-CAPTAIN