Repository navigation
WIP: #2212 bats cells — prelude heredoc closer, ambient fd delivery, EXIT-trap once-only, DEBUG silence in EXIT action - #2471
Merged
Conversation
…its own line
background_function_prelude serialized each function as
'name() { <body>;}' — when the body ends with a heredoc delimiter
line, the ';' lands ON the delimiter line, the heredoc is
unterminated, and every async respawn from a table containing a
heredoc-bearing function dies at parse (bats' usage() is such a
function; bats.bats test 118). GNU print_cmd.c:1053
print_deferred_heredocs: a bare ';' connector is swallowed before
heredoc bodies print, so the delimiter never shares its line —
the same rule as the #2388 closer in function source text and
the prelude's own '&' case (print_cmd.c:1520-1529 semicolon()).
render_ended_with_heredoc is now pub(in crate::executor) and the
prelude closer takes the newline form when the body ends with a
heredoc. Probes: heredoc fn + 'echo hi &' clean; async child
declare -f byte-identical to GNU bash 5.3.20.
Refs #2212
…bient pass for the input-procsub spawn Two halves of one mechanism (GNU fork inheritance carries the descriptor itself — execute_cmd.c; subst.c:6362 process_substitute): 1. An ambient fd >= 3 bound to a standard-stream endpoint (FdWriteEndpoint::Stdout/Stderr, FdReadEndpoint:: InheritedProcessStdin — what 'exec 3<&1' / '3>&2' / '3<&0' create) carries no FileFd handle, so every cross-process delivery transport dropped it and children died with EBADF. New FdReadEndpoint/FdWriteEndpoint::standard_backing(); ambient_procsub_spawn_fd falls back to it (wrapping a DUPLICATE — FileFd's Drop closes its handle, and the raw standard handle is the shell's own stdio); the external ambient pin pass and the async respawn ambient pass deliver the backing too. The respawn restore (init.rs) now prefers the stamped descriptor when it is actually open in the child: the whitelist transport delivers extras at their stamped numbers, and the at-slot adoption from #2333 bound the child's own read-only script file for these deliveries. 2. spawn_input_process_substitution_child had NO ambient fd pass at all (not even File endpoints) — the rubash#2466 face ('exec 9>ps.txt' + 'cat <(foreign ... >&9)'). It now runs the same adjudication: env stamps for rubash children plus pin_ambient_fds_in_child pre_exec pins (#1626's transport) so foreign children get the raw descriptors at their slots. Verified: bats.bats 118 shapes (input procsub 3<&1, pipeline-stage tee >(cat >&3), external child) byte-clean; async '{ echo >&3; } &' delivered; #2466 repro prints ps=[viaps] with 'p' in ps.txt, matching GNU; issue1626 pins 12/12 (was 11/12). Refs #2212
GNU runs the EXIT trap exactly once per shell exit (shell.c
exit_shell -> trap.c run_exit_trap). Rubash's exit funnel is
entered from several paths (the exit builtin's dispatch, the
script finish, subshell finishes), and take_exit_trap's take
semantics alone do not stop a second entry from firing an
action the first handler RE-REGISTERED while running — bats'
exec-suite teardown does exactly that ('avoid being called
twice'), which doubled its failure block (bats.bats test 133).
New Executor::exit_trap_ran latch: set when an action actually
runs; later funnel entries for the same executor return the
status without running anything. Probe: wrapper/inner
re-registration prints WRAPPER/INNER only, exit status kept;
issue1012 exit-trap pins stay 8/8.
Refs #2212
…runs GNU gates every run_debug_trap call site on 'signal_in_progress (DEBUG_TRAP) == 0 && running_trap == 0' (execute_cmd.c:704/3047/3519/...; trap.c:1263 run_debug_trap). Rubash fired the DEBUG trap for the EXIT handler's own first command, shifting bats' captured stack ring (bats.bats tests 55/57/59/64). The EXIT action now executes with debug_trap_running held (save/restore) as the running-trap umbrella bit. The ERR/RETURN/signal running flags are deliberately NOT consulted in the funnel: the post-ERR re-presentation seams run inside the ERR bookkeeping window, and gating on them silences firings GNU makes (probe rDbg: DEBUG fires between the inner and outer ERR firings; the funnel output is byte-identical to GNU 5.3.20 after this change, and the EXIT handler takes no DEBUG firing). Refs #2212
Extends tests/issue2212_bats_remainder_regressions.rs with pins 07-13: heredoc function vs the async prelude (07), ambient std-stream fd into an input procsub (08), into a pipeline stage's output procsub (09), into an async group (10), ambient exec-fd visibility for input-procsub children incl. a foreign child (11, the #2466 shape), EXIT-trap once-only under handler re-registration (12), and DEBUG silence inside the EXIT trap action (13). All expectations are GNU bash 5.3.20 behavior; 15/15 in the scrubbed-fd batch. Refs #2212
Member
Author
|
Verification correction (post-delivery): the regression ledger has one more run than the PR body lists. Alongside the two direct full runs at 222 passed / 6 failed (stock baseline set), ONE scrubbed full run measured 221/7 (278.88s under extreme load) with an extra failure in |
caomengxuan666
marked this pull request as ready for review
November 1, 2026 15:06
This was referenced Nov 1, 2026
Closed
Closed
caomengxuan666
added a commit
that referenced
this pull request
Nov 2, 2026
…m (rubash#2492) GNU basis: `exec 8<&0` is the dup branch of do_redirection_internal (redir.c:1192 — `dup2 (redir_fd, redirector)`), leaving fd 8 on the process stdin's open file description, and process_substitute (subst.c:6362, make_child at subst.c:6412) is a pure fork: the child inherits that descriptor whole, reads through it consume the same description, and `exec 0<&8` inside the child is a legal dup. Residual of #2471's half (a): spawn_input_process_substitution_child (executor/trap_exec.rs) had its ambient `__RUBASH_FD_*` pass behind #[cfg(unix)] — the Windows streamed producer spawn delivered NO ambient fd at all, std-stream or File, so after `exec 8<&0` a `<( ... <&8 ... )` body failed with `8: Bad file descriptor` (the modernish _Msh_loopgen `exec 0<&8` face). issue2212 pin 08 covered the collected comsub route (body runs in-process), so the Windows streamed spawn was never exercised. Fix: the pass now runs on every platform. On Unix nothing changes (the pins still dup2 each dup onto its slot in pre_exec); on Windows std's plain Command::spawn sets no PROC_THREAD_ATTRIBUTE_HANDLE_LIST (verified in the rustc 1.99 toolchain source — STARTF_USESTDHANDLES with bInheritHandles=TRUE), so the stamped inheritable dups cross at their own handle values, exactly what the child's init already trusts verbatim (init.rs, "Windows handle values transfer verbatim across CreateProcess inheritance") — the same transport the output form's plain spawn (external_setup.rs) uses. Std-stream endpoints arrive materialized through ambient_procsub_spawn_fd's standard_backing dup (#2212), so `8<&0` / `8<&1` / `8>&2` all ride as Files. Verification (WSL GNU Bash 5.3.x script files, stdin fed both sides — the fd is a dup of stdin, an unfed run blocks GNU in the child's read <&8): - repro byte-identical (parent got: [child sees fd8: [DATA-LINE]] / [ child exec 0<&8 ok]). - matrix {8<&0, 8<&1, 8>&2} x {<(...), >(...)} x {read / write / exec dup}: 6 semantic cells byte-identical on stdout/stderr or the side-file channel; artifacts under target/issue-suites/results/issue2492/. - new pins tests/issue2492_procsub_std_endpoint_fds.rs: 6/6. - issue2212 14/14, issue2292 18/18; issue2195 reds (7) verified identical on clean master 37eef11 (pre-existing Windows consumer-face gaps); cargo test --lib parity with clean master: 1124 passed / 2 failed / 3 ignored on BOTH trees (same 2 pre-existing reds). Hook note: committed with --no-verify because the repo-wide `cargo fmt --check` fails with os error 206 on this machine in the pristine main checkout too (argument line over the Windows limit with this many test targets) — the hook cannot execute here. Both staged files verified with per-file `rustfmt --edition 2021 --check`: clean, except one PRE-EXISTING master-side diff in trap_exec.rs at line 387 (present on committed master, untouched). Refs #2492 #2471 #2480
caomengxuan666
added a commit
that referenced
this pull request
Nov 2, 2026
…livery contract Refs #2521 Regression of the #2333 carrier restore, bisected: the pins in tests/issue2333_inherited_carrier_restore_regressions.rs pass 7/7 at 7a66413 (PR #2470) and fail 5/7 at e6ccbf1 (PR #2471). The regressing commit is ec40a88 ("deliver ambient std-stream fds across child spawns"), which added an occupancy probe to the startup restore: "prefer the stamped descriptor when it is open in this child". GNU semantics (the spec): a forked child inherits the parent's whole descriptor table, each descriptor keeping its own open file description (bash-5.3 execute_cmd.c, execute_in_subshell, :1576). rubash materializes that inheritance through spawn-time pins plus the __RUBASH_FD_HANDLE_<slot> stamps, and the restore must reconstruct each slot from the descriptor the TRANSPORT actually delivered: - pin transports (external ambient pass, input/output procsub, coproc): the carrier is pinned AT the slot fd; the stamp records the PARENT's descriptor number, which designates nothing in the child (the #2333 at-slot adoption rule, 8105a63). - whitelist respawn transport (fd::spawn_whitelisted, sole caller execute_background_ast_command): each extra crosses AT its stamped number; the child's raw slot fd can be its own read-only script file (the #2212 EBADF case ec40a88 was protecting). The occupancy probe cannot tell these apart: the pin pass stages each carrier above the ceiling and dup2s it onto its slot, leaving the staging sources open — so in a pin-delivered child the stamped number of slot N is open and holds a leftover copy of ANOTHER slot's carrier. The probe adopted those leftovers and rotated every carrier by one (n3 got body-four, n4 got the already-consumed carrier: EOF). Fix by mechanism: the spawner declares its delivery contract and the restore obeys the declaration instead of inferring it from fd occupancy. execute_background_ast_command — the only whitelist spawner — now sets __RUBASH_FD_AT_STAMPED=1 in the child env; the startup transport-key consumption removes it (it never surfaces as a shell variable or rides the env mirror) and the restore adopts the stamped descriptor only when the key declared at-stamped delivery. The fcntl occupancy probe is deleted; the #2333 at-slot rule is unchanged for every pin transport, and the Windows path (stamped value verbatim) is untouched. Verification (build slot, scrubbed_cargo.py cargo test): issue2333_inherited_carrier_restore_regressions 7/7 (was 2/7), issue2212_bats_remainder_regressions 15/15, issue2256_devfd_fresh_open_regressions 25/25, issue2479_devfd_reopen_cursor_regressions 8/8, issue2502_pipeline_alias_delivery_regressions 6/6, issue2476_born_closed_stdout_regressions 7/7, issue2484_stage_fd3_delivery 4/4.
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.
WIP: #2212 bats-cells cluster — do not merge (captain harvests).
Refs #2212
Five commits, one per mechanism family, each with GNU C citations
in the commit body:
prelude put its
;}closer on the heredoc delimiter line, so anyrespawn from a table with a heredoc-bearing function died at
parse. print_cmd.c:1053.
rubash#2466 repro) — std-stream endpoints (
exec 3<&1etc.)carried no FileFd and were dropped by every spawn transport;
the input-procsub spawn had no ambient pass at all.
subst.c:6362. issue1626 pins 12/12 (master 11/12).
the trap at
exitdispatch and again at finish; a handler thatre-registers mid-exit (bats' exec-suite teardown) fired twice.
face b) — GNU's
running_trap == 0gate at everyrun_debug_trap call site.
Verification (captain-style, scrubbed fds)
baseline set; no new reds.
host_internal_trap_suppression 1/1.
5691eff (stash-rebuild verified), not a regression.
Per-cell verdicts (full detail in the cluster REPORT)
formatter is waited for (report.log correct); residual raw
stream leak + rc=1 only in the --report-formatter pipeline
(bats_tee's
tee >(cat >&3)inside a pipeline-stage function).residual bare callback line from an ERR re-presentation at
EXIT-trap entry (marker-verified, minimal repro not isolated).
(post-abort DEBUG re-presentation on the DISCARD path) root-caused
with an empirical arming-dependent count law, GNU call site
unsettled, no speculative code landed per repo rules.
into the exec'd test child without their handler functions
(
bats_debug_trap: command not found), confirmed in-situ.lagging TAP stdout (formatter-pipeline flush discipline,
复合管道元向外部命令输出超 ~128 KiB 即死锁(有界 materialize 缓冲无人抽水) #2244 family); byte-level diff in the report.