Repository navigation
fix(executor): keep the export mark on an imported SHELLOPTS/BASHOPTS (Refs #3517) - #3536
Merged
Merged
Conversation
… (Refs #3517) GNU variables.c:506-517 initialize_shell_variables binds an imported SHELLOPTS/BASHOPTS like every valid-name environment entry, with att_exported|att_imported (the `ro` branch only adds ASS_FORCE and re-asserts att_readonly); the rebuilds (builtins/set.def set_shellopts, builtins/shopt.def set_bashopts) go through bind_variable, which keeps attributes. Rubash listed both names as bash-managed "never imported" names, so the import dropped the export mark: `declare -p` printed `-r` instead of `-rx`, `env` lacked them, and a child shell fell back to the default option set instead of the parent's live `set -o`/`shopt -s` state. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
marked this pull request as ready for review
November 14, 2026 04:55
caomengxuan666
marked this pull request as draft
November 14, 2026 05:09
Member
Author
|
【WIN-AGENT-AUDIT】 PR #3536 第1轮 — 建议:PASS 机制核查:
腿:
F 点:无 未跑/VOID 的腿:无(lib base 集复用同 merge-base 实跑结果)。 |
This was referenced Nov 15, 2026
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:03
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.
修了什么
从环境导入的
SHELLOPTS/BASHOPTS保留 export 属性(declare -rx),于是set -o/shopt -s的现行状态经由导出值传给子 shell,env里也能看到——与 GNU 一致。未从环境导入时两名仍只读不导出(守门格)。机制面:
src/executor/env_helpers.rsis_bash_managed_shell_var()名单把 SHELLOPTS/BASHOPTS 也列成「从不来自环境」的托管名,is_initial_export_candidate()因此不给导入值打 export 标。两名移出名单即可:导入值仍由initialize_fresh_shell_env_vars的选项回放消费(init.rsimported_shellopts/imported_bashopts),之后原位重建,export 标随之保留(mark_initial_exported_vars在重建之前扫表,故未导入的情况不会被误标)。删了什么
is_bash_managed_shell_var()名单里的"BASHOPTS"、"SHELLOPTS"两项。GNU 依据
variables.c:506-517 initialize_shell_variables():ro = STREQ (name, "SHELLOPTS") || STREQ (name, "BASHOPTS")分支只加ASS_FORCE并补att_readonly;VSETATTR (temp_var, (att_exported | att_imported))对两名同样执行。builtins/set.defset_shellopts()/builtins/shopt.defset_bashopts():重建走bind_variable,保留既有属性。与 #3517 原表的关系(实测,非推断)
#3517 正文所列「静态快照」各形状在现行 master(8b48c164)不复现:
set -e/set +B/set -o pipefail|posix后读$SHELLOPTS、-e/-o posix命令行、SHELLOPTS=posix:noglob导入驱动选项、shopt -s后读$BASHOPTS均与 GNU 5.3.20 逐字一致(探针与两壳输出贴在 issue 评论里)。正文所述src/runtime/options.rs/session.rs在本仓不存在。真正复现的是「env 输出 / 子 shell 继承」两格,根因是本 PR 修的导入丢 export 标。故用 Refs,是否据此关单由 owner 定。验证
tests/issue3517_shellopts_import_export.rs(5 格,期望来自 WSL GNU 5.3.20 脚本文件实测):修前 1 passed / 4 failed(仅「未导入守门格」过),修后 5/5。cargo test --lib env_helpers:2/2。third_party/bash/tests到 target/ 下以${THIS_SH} ./X.tests运行,diff --strip-trailing-cr对 .right):varenv修前 17 / 修后 17 差异行、输出逐字节相同;invocation修前 4 / 修后 4,输出仅 argv0 名不同。cargo fmt --check因 Windows 命令行过长(os error 206,1500 个 test target)无法运行;改用git ls-files '*.rs' | xargs rustfmt --edition 2021 --check全树检查,本 PR 文件干净(唯一 diff 是 master 上既有的tests/d11_pipeline_squote_carrier_regressions.rs)。因 hook 同样被 206 卡死,提交时 hook 走了其「cargo 不在 PATH 则跳过」分支——如实记录。Owed
export RO=v撞 readonly 不设 export 属性另立 [bug] export NAME=v 撞 readonly 时不设 export 属性(GNU setattr.def 赋值失败后仍 set_var_attribute) #3533。本 PR 均未涉及。