Repository navigation
WIP: coproc $! 进程保真:简单外部命令直 spawn (#1584);#1582 裁定材料+契约钉 - #2019
Merged
Merged
Conversation
GNU execute_coproc forks once and the child execs a simple external
command itself (execute_cmd.c:2525 make_child), so the coproc pid IS
the program's pid. rubash's respawn route put a rubash -c wrapper at
$!, running the command as a grandchild: comm($!) read rubash and
kill $! terminated the wrapper, never the command.
plan_direct_coproc_command admits a coproc to a direct spawn only
when parent-side evaluation is provably identical to the child's
fork-context evaluation: simple command, no tempenv prefix, no
command/process substitution or arithmetic expansion, no
process-identity dynamic variables (BASHPID/PPID/BASH_SUBSHELL), no
RANDOM draws, no procsub or {fd} redirect targets, nounset/failglob
decline on any expansion or glob word, the expanded head must not
resolve to a function/alias/builtin/keyword, and the target must be
a kernel-exec'able image (ELF/Mach-O/#!) so the ENOEXEC
run-as-shell-script fallback stays with the wrapper. Every miss
falls back to the unchanged respawn route. Direct children get the
ordinary external environment, not the shell-state snapshot; pipes,
redirects, job registration and COPROC endpoint binding share the
existing tail. Windows keeps the respawn route.
Seed shape plus the fidelity surface: $! names the program for coproc cat, /bin/cat, grep with args and a named coproc (NC_PID); kill -TERM $! reaches the command itself (comm=sleep, wait 143); the fds stay 63,60 and the data round-trip is unchanged. Negative control: a builtin coproc (read) keeps a shell-image child, the GNU-faithful shape for shell-image coprocs.
Three invariants that hold on current master and that any resolution of the flat-level BASHPID projection must preserve: a spawn-realized (async) subshell's BASHPID equals the PPID its children observe; $PPID stays frozen at its startup value inside a subshell (GNU set_ppid runs once at init); kill $BASHPID inside a flat subshell stays scoped to that layer (dies 143, host lives). No behavior change; the projection question itself is left open for adjudication with the shape table in the PR.
…584-1582 # Conflicts: # tests/regression.rs
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.
进程身份面双单:#1584 已修;#1582 交付裁定材料(形状表 + 方案代价),保持 open。
#1584 — coproc $! 进程保真(已修)
GNU
execute_coproc只 fork 一次、子进程直接 exec 简单外部命令(execute_cmd.c:2525make_child(FORK_ASYNC)),所以 $! 就是程序本体的 pid。rubash 的 respawn 路线把rubash -c包装进程放在 $!:ps -o comm= -p $!读到 rubash、kill $!只杀包装(被杀的 sleep 本体无人发信号、成孤儿),进程树保真度失真(wait 状态 143 数字相同、树不同,双跑实测见 REPORT)。修法(
plan_direct_coproc_command,unix;Windows 维持 respawn):白名单准入直 spawn,任一条件落空回既有 respawn 路线,miss 只损失保真度、永不损失语义:set -u下任一展开、failglob下任一 glob 词回退;{fd}分配回退;#!)且有执行位——ENOEXEC 在 GNU 是子进程内按 shell 脚本重跑,只有包装路线能复现。直 spawn 的环境走普通外部命令的
apply_external_environment,不带 shell 状态快照与__RUBASH_*键;管道/stderr 计划/重定向/job 注册/COPROC 绑定与修前共用同一尾段。残差:展开在父进程同步发生(准入类已限定为等值展开,仅剩超大目录 glob 的时序差)。钉(tests/regression.rs
mod issue_1584,CI regression 目标覆盖):种子形 comm=cat + fds 63,60 + 回环 + rc 0;kill 达本体(comm=sleep/143);/bin/cat;带参 grep;具名 coproc 的 NC_PID;负对照 builtinread保持 shell 镜像(comm=rubash)。Fixes #1584
#1582 — 平坦子壳 $BASHPID 合成值(待裁定,不在本 PR 修)
双跑形状表(节选;全表在工区 REPORT):
( ) &/ procsub 生产者( )深度 1/2、命令替换、管道 brace 阶段$PPIDkill -TERM $BASHPID裁定要点:no-fork 前提下 $BASHPID 至多满足 {=真实子进程 PPID、每层互异、kill 只作用本层} 中的两条,GNU 靠真实进程三条全得。方案 A 维持现投影(选互异+kill 作用域);方案 B 取最近 realized 祖先真实 pid(得交叉核对、失互异,且 kill 拦截须特判——会吞掉子壳内合法的「杀主 shell 真实 pid」,风险高);方案 C 每层真进程与架构前提冲突。issue 原立案口径即「与状态视图线一并裁定、不做点补」。建议维持 A 并把投影规则写进状态视图文档;本 PR 只落三条与裁定无关的既有契约钉(realized 层一致性 / PPID 冻结 / kill 作用域——方案 B 若被采纳,第三条是其必须守住的安全线)。
Refs #1582
门
cargo check --locked --libwithRUSTFLAGS="-C debuginfo=0 -D warnings"干净通过(单次不间断运行、产物核验);per-file rustfmt 已过;CR 计数 0。