Repository navigation
parser/executor: recover capture-span relative lines for folded brace groups and procsub seeds - #3297
Merged
Merged
Conversation
… groups and procsub seeds Refs #3210 Two loss points, one fix per mechanism: - Lexer: refuse to fold a `{...}` group when a continuation join falls inside its span (scanner.rs `{` arm). The folded value loses the joins, so the body re-lex reports every command on the group's first line (GNU: each first element's physical end line, parse.y:5849 simplecmd_lineno, execute_cmd.c:936). The parser then takes the slice path with feeder-stamped tokens. One refusal covers all five folded-body re-lex consumers (function bodies, bare groups, for/select/C-for `{}` bodies, region scan). - Executor: seed every procsub spawn with procsub_body_seed_line (the enclosing simple command's first-element end line, execute_cmd.c:936) instead of cmd.line (the start line). Pins: tests/issue3210_procsub_body_split_word_end_line.rs grows to 32 cells (Residual B 7, guards 8, $LINENO 2, procsub seed 2, bare group 2, eval 1); the comsub cell's rc expectation is corrected 0 -> 127 against the GNU oracle. Compound-stdin procsubs (`{...} < <(...)`, `while ... < <(...)`) stay on the ambient line per execute_cmd.c:854 -- a separate residual, not covered here. Deleted: nothing (no code or tests removed; the temporary debug test was never committed).
This was referenced Nov 10, 2026
caomengxuan666
marked this pull request as ready for review
November 10, 2026 22:54
caomengxuan666
added a commit
that referenced
this pull request
Nov 10, 2026
…ed / (rubash#3268 (e)) (#3298) Refs #3268 (e) 启动面:已删 cwd 里出生的会话保有其 inode,不再被伪造的 `/` 移植。父进程坐在已删目录 inode 里拉起的 rubash 此前整场被移植到根目录:`pwd` 印 `/` rc 0、`$PWD` 被种为 `/`、子进程被盖戳进 `/`、`ls ..` 列根目录。 ## 机制 GNU 在启动期不持有 cwd 字符串状态——进程 inode 即状态;variables.c:907 `set_pwd()` 只种 `$PWD`(导入 PWD 仅当绝对且 `same_file(PWD, ".")` 时受信,否则走 builtins/common.c:592 的 `get_working_directory("shell-init")`,失败则 PWD 不绑定)。本 PR 让出生期服从与运行期同一条两态规则: - 出生 cwd 在 `Executor::new` 只捕获一次,同一值喂 env 种子与 ShellState 字段(此前两处独立 `current_dir()` 可跨 getcwd 边界互相不一致)。成功路零变化:字段 = 路径、PWD 照旧、锚保持惰性,respawn 热路径不新增 open。 - 捕获失败时字段取空路径——诚实的「未知」(永不解析、永不与真实目录相等)——出生锚以 `File::open(".")` 装入并命名该字段,两态机制(`stamp_spawn_cwd` 的 fchdir、`read_session_anchored` 的 openat)自此接管;首次成功 `cd` 自然退出异常态。 - PWD 种子在未知态不写:GNU 的 set_pwd 在 getcwd 失败时不重绑——有导入则保留陈值、无导入则保持未绑定,两种形态各有钉格锁定(此点为对 DESIGN §5.2.3 的源码订正,队长复核已亲读 variables.c 与 oracle 实测确认)。 - 新生(非 respawn)出生恰印一行 `shell-init:` 警告(strerror 文本经 `libc::strerror`,与 common.c 的格式逐字同构);respawn 子进程静默(GNU 的 fork 子不重跑启动);GNU 的逐命令 `job-working-directory:` 重复按队长裁定不跟。 - `pwd` 在空字段下双模式皆失败:stdout 空、`pwd:` 同式一行、rc 1(errno 文本为出生失败的 ENOENT 实测形;EACCES 出生失败同印此文本,为已注明的近似——本环境内核 getcwd 在父目录 chmod 000 下仍成功,该形态不可构造实测)。 - E6 respawn:`WhitelistedSpawn` 新增 `cwd_anchor_fd`(Windows 侧 parity 接收并忽略),不可解析时 spawner 在 fork 与 exec 之间 fchdir 进会话锚 inode——此前 async 子进程根本不盖戳、生在宿主进程 cwd;validated respawn 在出生 getcwd 失败时采信运输 PWD 为字段(GNU fork 子原样继承 `the_current_working_directory`),采信由 respawn 出身验证门把守、且 #3275 身份门保证该串永不冒充解析结果,环境 PWD 永不采信。 ## 本 PR 删除了什么 - `Executor::new` 里两处 `unwrap_or_else(|_| PathBuf::from("/"))` 出生回退(env 种子与 ShellState 字面量)——伪造本身。 - `initialize_fresh_shell_env_vars` 的无条件 PWD 写入(改按已知 cwd 条件写入)。 - fd/unix.rs 里「respawned child 从运输状态重导会话 cwd」的失实旧注释(运输层并无 cwd 键),替换为真实机制。 ## 队长复核(`~/workspace/review-3298/CAPTAIN-VERIFY.md`,全部独立复跑) - 头钉 11 过 / 0 红 / 1 ignore;ignore 格显式运行 1 过(归因见卷宗:绿来自空字段裸相对落出生 inode 的独立窗口,非锚定 serve——(a) 的收敛仍属必需,该格按预登记保持 `#[ignore]` 至 (a) 合入)。基底 fail-first 3 过 / 8 红 / 1 ignore,8 红逐名恰为修法目标格、3 过恰为对等锁格(abs_dead/recover/normal_birth);ignore 格基底显式运行亦红。 - 邻茎五茎各有独立 `test result: ok`(issue3198 7、issue3201 5、issue3275 4、issue2526 两茎 4 与 3);lib 双边先建 `--bin rubash` 后同为 1233 过 / 0 红 / 4 ignore,失败名集 ∅=∅。 - `RUSTFLAGS="-D warnings"` 本 PR 目标面(lib+bins+新钉,touch + `-v` 亲证真载)rc=0;`--all-targets` rc=101 的 error 全在未被本 diff 触碰的既存测试文件(#2631 在册的 --tests 警告债),与本 PR 零交集。fmt `--check`、marker-lint(117 注册常量、267 allowlisted sites)、UTF-8 边界卫生三腿 rc=0;armv7-linux-androideabi `cargo check --tests`(NDK r26d 配方)rc=0;darwin 以本 PR 自身 CI 为凭(Cross-target check (darwin) success)。 - PR CI 终局 10 success + 1 skipping、零红(canary 全绿);merge-tree 对 master `2ae82963` 零冲突、文件集恰 8。 - 合入轮(终头 `9ec2f1a7`,三轮 update-branch:master 经 `3a93856b`、`36590c5f`(#3283)、`2ae82963`(#3297)推进):终头全腿 box 复跑——头钉 11/0/1、ignore 格显式 1 过、邻茎 7/5/4/4/3、lib 1233/0/4 与基底失败名集差 ∅、`-D warnings` 目标面 rc=0(touch + `-v` 亲证带 flag 调用)、`--all-targets` error 文件集与基底逐字相同(16 个既存他茎文件,#2631)、fmt/marker/UTF-8 三腿 rc=0、armv7-linux-androideabi `cargo check --tests`(NDK r26d)rc=0、darwin 以终头 CI 的 Cross-target check (darwin) 与 macOS tests 为凭(success);终头 CI 10 success + 1 skipping 零红、canary 全绿。基底 fail-first 对照(钉拷入基底树)3 过 / 8 红 / 1 ignore、ignore 格基底显式运行亦红,与复核账一致。 - 硬门普查:头/基底两树 `.session_path(` 消费调用点共 86 处,逐文件计数与逐行抽查(trap_exec/compound_exec/shell_options/external_file_builtins/command_input_scope 五行全对)与车道普查表全合——重定向 60 归 (c)、模拟命令 8 归 (d) 与 #3276、comsub 2 归 (a),H 残窗与 G-H 残窗均按已知残窗诚实登记,无一冒充已覆盖。车道报告的标题总数「87」多计一处(path.rs:5273 系含 session_path 字样的测试名、非调用点),卷宗已订正,不影响覆盖完备性。 - 三方探针(GNU 5.3.20 / 基底 / 头树):出生各形(cat、pwd 未绑定、pwd 陈值导入、-P/-L、respawn 静默、comsub 快捷形)头树与 GNU 逐项一致(`job-working-directory:` 重复除外,按裁定不跟);运行期已删 cwd 的 `pwd -P` 印字符串一格头树与基底同(属已立案的 #2798 面,本 PR 不动)。 本 PR 只及五面中的 (e) 面,父单保持开启。
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 #3210
What
Two loss points made split first elements report the wrong diagnostic
line (head: line 1, GNU: line 2). One fix per mechanism — no
per-shape patches.
1. Lexer — refuse to fold a
{...}group when a continuation joinfalls inside its span (
src/lexer/scanner.rs{arm).A single-logical-line group is folded into one Keyword token and
re-lexed from the joined value, which has no newlines — so every body
command reports the group's first line. GNU reports each first
element's physical end line (
parse.y:5849-5851simplecmd_lineno,execute_cmd.c:936SET_LINE_NUMBER). The refusal emits the bareopener (mirroring the unclosed path), so the parser takes the
already-correct slice path with feeder-stamped tokens. The join list
is threaded from the feeder (
GroupScanFeeder::continuation_join_columns)through
tokenize_plain/tokenize_resume_from/tokenize_with_boundaryintoLexer::join_columns. One refusal coversall five folded-body re-lex consumers (function bodies, bare groups,
for/select/C-for{}bodies, region scan). Groups without a joinfold exactly as before (nvm shape untouched).
2. Executor — seed every procsub spawn with the first-element end
line (
src/executor/command_text.rs:304, newprocsub_body_seed_line).GNU sets the line before executing the simple command
(
execute_cmd.c:936) and the fork inherits it (subst.c:6362); thevalue already existed as
simple_command_first_word_end_line(usedonly by
set_current_line). Seven spawn sites passedcmd.line(thestart line) instead —
trap_exec.rs,external_setup.rs(
cmd_linebinding, feeds input and output spawns),read_io.rs,command_input_scope.rs(x2),read_redirected_fd.rs(x2). No
cmd-less site is touched.Pins
tests/issue3210_procsub_body_split_word_end_line.rs(new file,32 cells): Residual B 7, design guards 8,
$LINENOagreement 2,procsub seed 2, bare-group 2, eval 1. The comsub cell's rc
expectation is corrected 0 -> 127 against the GNU oracle (the head
tree already printed GNU's line-2 diagnostic; only the expectation
was wrong). The pin header's old mechanism note (re-print folding)
is corrected: the folding is harmless (equivalent to GNU's
child-side no-bump for
\<newline>in a word,parse.y:5377-5381).Out of scope, separate residual: compound-stdin procsubs
(
{...} < <(...),while ... < <(...)) stay on the ambient lineper
execute_cmd.c:854— see REPORT §7 for the filing draft.Verification
Head
243261b1on masterbc049e16; the patch is byte-identicalto the one verified below (conflict-free rebase,
git showdiffof the two commits differs only in the commit id and one base
blob index).
d7a37258: pin 3210 8/2 (comsub expectationcell + procsub defect cell), pin 3209 23/1 (pre-registered coproc
residual only).
3053 20/0, 3054 12/0, 1184 7/0, 2332 12/0, 2202 10/0, 3028 23/0.
bare-group and eval forms match byte-for-byte.
RUSTFLAGS="-D warnings"check (lib+bins): 0 warnings.cargo fmt --check: clean. Marker lint: OK.cargo check --tests: rc=0(pre-existing warnings only in untouched test files).
difference empty.
re-run went VOID on a quota wall: EDQUOT, build rc=101, logs
unwritable — not a product verdict). Box head (bc049e1 + this
patch): pin 3210 32/0; neighbours 3053 20/0, 3054 12/0,
1184 7/0, 2332 12/0, 2202 10/0, 3028 23/0; probes A + B rc=0;
-D warnings/ fmt / marker lint /cargo check --testsallrc=0; lib 1233/0/4.
cells:
background_first…and the pre-registered coprocresidual), lib 1233/0/4 on both sides — this patch introduces
no regression there.
background_firstis a pre-existingenvironment-sensitive cell (background-wrapper timing: line 2
on the box, line 1 locally and with GNU; the pin's line-1
expectation matches GNU); see REPORT §5.6/§7.2.
Full evidence:
~/workspace/fix-3210/REPORT.md.Deleted
Nothing (no code or tests removed; the temporary debug test was
never committed).