Repository navigation
fix(executor,builtins): #873 wrapper respawn carries the handshake argv flag only when the host CLI consumes it - #906
Merged
Conversation
…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.
SpookyWaste
pushed a commit
to SpookyWaste/rubash
that referenced
this pull request
Nov 12, 2026
Refs unixwin#863 本 PR 删除了什么:无(账本逐字同步,niubash unixwin#906 合入后的锁步镜像)。
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.
背景(发版阻塞)
#873 的不可伪造握手里,wrapper 重spawn 无条件向子进程 argv 附加 niu-CLI 专属旗标
--internal-bg-wrapper=<nonce>。niubash(内嵌本引擎)的 niu 启动器从不消费它——旗标进入启动器的 GNU 对齐选项解析,每个 wrapper 后台命令 spawn 即死: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 必消费)。修法(消费者在位门控)
consume_background_wrapper_handshake顶部无条件置BACKGROUND_WRAPPER_FLAG_CONSUMER(rubash main.rs 每次启动必调;采纳宿主做同一次调用即可)。API 不变,行为多一个进程级标记。background_wrapper_flag_consumer_present()门控;非消费者宿主得到 env-nonce-only 重spawn——env 键对非消费者惰性(不被读;任何真正启动的 rubash 会清洗它),单通道永不 arm,user-forgeable __RUBASH_BACKGROUND_WRAPPER env var imposes PDEATHSIG semantics on every spawned child #866 防伪造契约不变;getppid() == 1 orphan-race check self-kills healthy children under PID namespaces #867 期望父 pid 与 [S9] process ownership: kill does not terminate background shell children (and wait fabricates 128+n); no SIGPIPE for builtin writers #737 cascade 只对消费者路径生效,逐 spawn 等价。cfg!(test)分支:本 crate 单测进程不跑 main.rs,无此门则附加与否取决于握手单测是否先跑(顺序依赖);单测进程的 respawn 目标恒为本仓引擎二进制(CARGO_BIN_EXE / deps 兄弟目录探测),必是消费者,附加即 master 原行为。验证(全自跑)
宿主采纳契约:嵌入方在 CLI 启动时调用
consume_background_wrapper_handshake即恢复完整双通道握手(niubash 配套分支已做,#737 cascade 在 niu 上保持存活)。