Repository navigation
WIP: fix(executor): anchor function-call redirect operands at the session cwd - #2247
Merged
Merged
Conversation
GNU keeps exactly one cwd: cd moves the process's (builtins/cd.def change_to_directory -> chdir), and execute_function applies the call's redirections with do_redirections (execute_cmd.c:5181), whose redir_open (redir.c) opens the expanded word relative to that cwd. Under G-02 the process cwd never moves, so every operand resolution must anchor at ShellState.cwd via session_path. Three faces of the function-call / shared redirect machinery opened the bare mapped path instead, resolving against the startup directory after any cd: - function_call_stdin (function_calls.rs): a function call's `< file` (and a definition redirect's `<`, applied per call) missed files in the current directory — ENOENT, or the startup tree's same-named file read instead (t1300 alpha family). - stdin_string_for_command (shell_options.rs): the text channel's `<>` create and slurp open did the same, so a function call's `<>` staged the startup tree's file. - reject_invalid_redirects' ReadWrite probe (redirection.rs): the shared validation gate's `<>` probe creates its target (rubash#264) — unanchored, it planted a stray empty file in the startup directory for every command form and passed its verdict against the wrong file. All three now resolve through the ladder the other input faces already use — shell_path_to_windows, windows_operand_file_path, session_path — with the rubash#2211 empty-operand rule preserved (an empty word is never joined onto the cwd). Diagnostics keep naming the operand as spelled (path_error on the expanded target). Regression pins: tests/issue2240_function_input_redirect_cwd_regressions.rs (9 defect pins red on master 1d5d62d, 5 controls green; all 14 green with this change; probe battery V/W/X/X7/Y/E byte-identical to GNU bash 5.3.20). Refs #2240
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 #2240
问题
函数调用的输入重定向相对路径按进程启动 cwd 解析而非当前逻辑 cwd:
cd后g <f.txt对当前目录里的文件报 ENOENT(t1300 α 族 4 条)。#2211 的姊妹病、不同代码路径——#2211 锚的是 comsub 快捷路径,本条在函数调用重定向一线。GNU 依据:GNU 只有一个 cwd——
cd经 builtins/cd.def 的 change_to_directory 直接 chdir 进程;execute_function(execute_cmd.c:5181)以 do_redirections 应用调用的重定向,redir.c 的 redir_open 对展开后的词做普通 open,相对操作数即按 shell 当前目录解析。rubash 的 G-02 模型下进程 cwd 永不移动,一切操作数解析必须经session_path锚到ShellState.cwd。审计与修复(三处同病灶,统一走既有解析梯)
全仓盘点重定向操作数的裸 open 点后,确认三处未锚定(其余各面——简单命令
open_input_redirect、编号 fdopen_compound_numbered_input_redirects、复合 fd0compound_fd0_stream_file、函数输出侧create_redirect_output_prepared、动态 fd 与exec的set_fd_readwrite_file——均已锚定):function_call_stdin(function_calls.rs)——函数调用< file的实际绑定(含定义时重定向在每次调用时的应用):cd 后 ENOENT,同名文件在启动目录存在时还会读错内容。stdin_string_for_command(shell_options.rs)——文本通道对<>的预创建与 slurp open 未锚定:函数<>读到启动目录的文件/空文件。reject_invalid_redirects的 ReadWrite 探针(redirection.rs)——全命令形式共享的校验门:<>探针的 open 带 O_CREAT([bug] '<> file' does not create the missing file (GNU opens O_RDWR|O_CREAT; rubash fails ENOENT) #264),未锚定时在启动目录留下一个空的杂散文件,且对着错误文件下校验结论(简单命令cat <>new在两个目录各建一份即此)。三处统一改为与其余输入面相同的解析梯(
shell_path_to_windows→windows_operand_file_path→session_path),并保留 #2211 的空操作数规则:空词永不 join 到 cwd(否则会把会话目录本身制造出来)。诊断继续按展开后的操作数原样命名(path_error 吃 target 本身),不暴露锚定后的绝对路径。验证
tests/issue2240_function_input_redirect_cwd_regressions.rs(14 条):基线(master 1d5d62d)9 红 5 绿(5 绿均为对照:启动 cwd、绝对路径、编号 fd、缺失文件诊断、输出侧锚定),修复后 14/14 绿。<>、定义时重定向按调用时 cwd、..、ENOEXEC 子脚本形状)修复后与 GNU bash 5.3.20 逐字节一致,含目录树(<>创建落点)与 stderr。范围外(已在簇 REPORT 记录、供主会话立案判断)
函数调用
<>的写面(函数体向 fd 0 写)在基线上即与 cwd 无关地坏(echo x >&0报 Bad file descriptor)——属 fd-0 写端点建模的独立缺口,本 PR 不动。