Skip to content

fix(executor,builtins): #873 wrapper respawn carries the handshake argv flag only when the host CLI consumes it - #906

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/873-bg-flag-consumer-gate
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/873-bg-flag-consumer-gate

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

背景(发版阻塞)

#873 的不可伪造握手里,wrapper 重spawn 无条件向子进程 argv 附加 niu-CLI 专属旗标 --internal-bg-wrapper=<nonce>。niubash(内嵌本引擎)的 niu 启动器从不消费它——旗标进入启动器的 GNU 对齐选项解析,每个 wrapper 后台命令 spawn 即死:

bash: --internal-bg-wrapper=<nonce>: invalid option  (+ usage, rc 2)

niubash master CI tests/background_spawn_args.rs 两红(background_command_keeps_dash_dash_args_out_of_host_cli、large_function_table_background_command_runs)。本仓 Ubuntu CI 未红是因为 respawn 目标恒为本仓引擎二进制(main.rs 必消费)。

修法(消费者在位门控)

验证(全自跑)

宿主采纳契约:嵌入方在 CLI 启动时调用 consume_background_wrapper_handshake 即恢复完整双通道握手(niubash 配套分支已做,#737 cascade 在 niu 上保持存活)。

…e argv flag only when the host CLI consumes it

The --internal-bg-wrapper=<nonce> channel is niu-CLI-specific. The wrapper
spawn site attached it unconditionally, so any host that never consumes the
handshake received an unknown option in its respawned argv: the niubash
launcher (which embeds this engine) answers with the GNU-aligned usage
error — bash: --internal-bg-wrapper=<nonce>: invalid option + usage, rc 2 —
and every wrapper background command died at spawn (niubash master CI,
tests/background_spawn_args.rs 2 red). A foreign bash face would reject it
the same way.

Gate the attach on a process-level consumer bit:
consume_background_wrapper_handshake now marks the CLI at its very top
(rubash main.rs calls it at every startup; adopting hosts make the same one
call — niubash does, in the companion launcher commit), and the spawn site
splices the flag only when background_wrapper_flag_consumer_present() is
set. Non-consuming hosts get env-nonce-only respawns: the env key is inert
for a non-consumer (never read; any rubash that does start scrubs it) and a
single channel can never arm, so the #866 forgery contract is unchanged;
#867's expected-parent check and the #737 cascade are untouched for
consuming hosts.

cfg(test) keeps the attach unconditional in this crate's unit tests: the
harness process never runs main.rs, so without it the attach would be
order-dependent on the handshake unit tests; there the respawn target is
always this repo's own engine binary (CARGO_BIN_EXE /
test_rubash_binary_from_current_exe), a consumer by construction.

Verified: WSL lib 634/634 (incl. the new consumer-bit unit test), tests
issue866 4/4 (W1 #737 cascade intact through the real binary) + issue867
2/2 (unshare namespace probes), Windows family issue294/382/549/550 28/28,
catalog issue-866 match + issue-737 still diverges, fmt clean, -D warnings
clean for lib+bins; niubash companion branch flips the two CI-red tests
green against this tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant