Repository navigation
fix(cd): emit GNU's chdir: diagnostic on cd entry in a poisoned cwd (Refs #3574) - #3713
Merged
Merged
Conversation
…Refs #3574) In the poisoned-cwd state (a failed `pwd -P` went through resetpwd and left the_current_working_directory NULL, rubash#3349), GNU's change_to_directory re-derives at entry through get_working_directory ("chdir") (builtins/cd.def:529-534, builtins/common.c:592-624): a failing getcwd prints `chdir: error retrieving current directory: ...` and the move still stands. rubash emitted no such line. The entry fires once per change_to_directory call — the CDPATH candidates in order, then the plain operand, then the cdable_vars value (oracle: 1 failed CDPATH unit + hit = 2 lines; 2 failed units + plain fail = 3; cdable_vars success = plain + cdable_vars = 2) — so resolve_cdpath now also reports how many candidates it probed, and the entry block emits that many lines when the session logical cache is poisoned (logical_cwd is None) and the re-derivation fails. A succeeding re-derivation silently restores the cached value, as in GNU. Early returns (bad options, too many arguments, unset HOME/OLDPWD, null directory) never reach change_to_directory and owe no line. Companion correction in the same state: for a dot-only operand GNU's make_absolute base is NULL, so canon cannot fail on a deleted component and the verbatim chdir's resetpwd arm (the `cd:` line rubash#3335 owes) never runs — the entry `chdir:` line is the only diagnostic (oracle p5/p12). The stayed_deleted_dot diagnostic is suppressed while poisoned; the unpoisoned face is unchanged. Tests: new tests/issue3574_cd_deleted_cwd_chdir_diag.rs (10 cells: absolute / CDPATH / dot / dotdot / no-arg / cdable_vars / too-many / null / unpoisoned control); #3349 cell5 now expects the `chdir:` line as well. UNVERIFIED-BY-CAPTAIN: all verification legs OWED (remote build routes down, no local builds) — nail fail-first/green, neighbour stems (#3349, #3335, #2796, #3394, #3395), full lib vs base, RUSTFLAGS="-D warnings" check, GNU-vs-rubash binary comparison. Local-only checks done: rustfmt --check on the three touched files, check-marker-literals.py OK, git diff --check clean. 本 PR 删除了什么:无。仅新增诊断输出与回归钉;resolve_cdpath 的返回由 Option<Target> 改为 (Option<Target>, usize),为私有 函数,无公开面变化。
…sue3574 nail (Refs #3574)
… nail (Refs #3574) The nail's poison_script runs both `pwd -P` and `pwd` after the rmdir, so GNU 5.3.20 emits two GETCWD diagnostic lines before the cd entry's `chdir:` line(s). Six cells asserted one; cell3 also asserted two pwd faces while GNU's trailing pwd after the failed cd re-derives a third time. Verified against the WSL GNU bash 5.3.20 oracle and the fixed rubash binary (byte-identical, 2 pwd + 1 chdir / 2 pwd + 2 chdir).
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
续作记录(本轮动过代码):
腿(逐项给数字与名字):
F 点:无。 未跑/VOID 的腿:
|
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 #3574
根因
中毒态(
pwd -P在 deleted cwd 失败,经 resetpwd 把the_current_working_directory置 NULL,rubash#3349)下,GNU 的change_to_directory入口在tcwd == NULL时调get_working_directory ("chdir")重推导,getcwd 失败即打印chdir: error retrieving current directory: …,然后照常 chdir、照常成功。rubash 的cd入口没有这一步,全程静默。GNU 锚点(bash 5.3):
builtins/cd.def:529-534change_to_directory入口:if (the_current_working_directory == 0) { t = get_working_directory ("chdir"); FREE (t); }builtins/common.c:592-624get_working_directory:getcwd 失败打印for_whom: error retrieving current directory: getcwd: cannot access parent directories: …(bash_getcwd_errstr,general.c:70)builtins/cd.def:353-388CDPATH 循环(每单元一次change_to_directory调用)、cd.def:397-405cdable_vars、cd.def:329-336early return(too many / null directory 在change_to_directory之前返回)修法(
src/builtins/cd.rs,唯一产品文件)execute_with_io在resolve_target/resolve_cdpath/resolve_cdable_vars之后、move 探针之前插入入口重推导块:中毒态(logical_cwd is None,唯一置 None 处是 #3349 的中毒路径)时以cwd.canonicalize()(session cwd 字段即本移植的 getcwd 真值)重推导——成功则无诊断且把缓存值恢复为物理拼写(与 GNU 一致);失败则按调用次数打印chdir:行,然后照常走 move。调用次数 = CDPATH 探过的单元数(命中则止;未命中则 +1 plain 尝试,+1(若 cdable_vars 值被替换));为此resolve_cdpath返回(Option<Target>, usize)。early return(bad options / too many / HOME·OLDPWD 未设 / null directory)皆在块前,无行。同态附带修正:
deleted_dot_move的stayed_deleted_dot(#3335 的cd:resetpwd 行)在中毒时置None——GNU 中毒态下 make_absolute 的基是 NULL,./..的 canon 不可能因已删分量失败,verbatim chdir 后的 resetpwd 臂根本不跑(oracle p5/p12 只 1 行chdir:、无cd:行)。未中毒态的cd:行不受影响。Oracle 实测(GNU bash 5.3.20,脚本文件形):绝对 cd 中毒后恰 1 行;CDPATH 一败一中 2 行、两败 + plain 败 3 行;cdable_vars 成功 2 行;失败 cd 仍有 1 行;
cd a b/cd ""0 行;cd ./cd -P .中毒后仅 1 行chdir:、无cd:行;未中毒对照 0 行。测试
tests/issue3574_cd_deleted_cwd_chdir_diag.rs(Unix-only,10 cell:绝对 / CDPATH /./../ 无参 / cdable_vars / too-many / null / 未中毒对照)。tests/issue3349_pwd_poisoned_logical_cache.rscell5:期望 stderr 由 2×pwd:改为 2×pwd:+ 1×chdir:(该 cell 原称此行「owed separately」,现由本单支付)。已知残差(本单不修,见 REPORT)
./..),rubash 绑 stale 基的逻辑目的——另立案。cd_builtin移动,中毒态下也应报chdir:行;rubash pushd 不走cd::execute_with_io——另立案。is_none())不覆盖,需单独分析。本 PR 删除了什么
无。仅新增诊断输出与回归钉;
resolve_cdpath的返回由Option<Target>改为(Option<Target>, usize),为私有函数,无公开面变化。UNVERIFIED-BY-CAPTAIN
全部验证腿 OWED(远程构建路线全断:Simular box 钱包空 hibernated,老服务器与 X299 均须经 box 中转同断;本 VM 禁本地构建且内存低于构建门):钉 fail-first 红 / 修后绿、邻居 stem(#3349、#3335、#2796、#3394、#3395)、全量 lib 与 base 双边、
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、GNU-vs-rubash 二进制对照。本地已跑:rustfmt --check(三文件)、check-marker-literals.py OK、git diff --check 干净。REPORT:~/workspace/fix-3574/REPORT.md。