Repository navigation
fix(executor): coproc 子进程继承父函数表快照,DEBUG trap 函数可解析 (fixes #441) - #469
Merged
Merged
Conversation
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.
closes #441
问题
GNU
coproc通过 fork 创建 coprocess(execute_cmd.ccoproc_getfd->make_child),子进程完整继承父 shell 的函数表。rubash 的 coproc 是 spawn 一个新的内部rubash -c子进程,此前只传递了导出变量与 trap 状态,没有传递函数表。于是 coproc 之前安装的 DEBUG trap(如 oh-my-bash 的 bash-preexec 注入的__bp_preexec_invoke_exec)在子进程里触发时解析不到函数定义,退回 PATH 查找并报command not found(每条命令两次)。修复
execute_coproc_command(src/executor/compound_exec.rs)在 spawn coprocess 子进程时,把父 shell 的完整函数表以BASH_FUNC_name%%环境项的形式做成快照传给子进程(Executor::new启动时导入为函数并剥离载体键)。语义与 GNU fork 对齐:export -f语义不变。验证
trap 'preexec' DEBUG+coproc):修复前子进程报preexec: command not found,修复后输出PREEXEC: inside-coproc,无诊断噪音。D:\Git\usr\bin\bash.exe)运行同一脚本。coproc + DEBUG trap + 函数表是 5.x 稳定语义,5.2 可作对照;oracle 下 coproc 子进程正常执行preexec inside-coproc,与本修复行为一致。未观察到语义差异。coproc_child_inherits_function_table_for_debug_trap:DEBUG trap 在子进程内成功调用父函数;coproc_function_snapshot_is_one_way_into_child:子进程可见函数、父进程函数表保留且无新增导出(单向快照)。cargo test --test cli_tests -- --test-threads=1 process_substitution全绿;--test issue352_coproc_reap_regressions全绿;--lib624 全绿。cargo fmt已执行。