Repository navigation
fix(subst,executor): #825 set -T DEBUG trap into $( ) + #826 compound redirect-failure diagnostic via the fd table - #842
Merged
Merged
Conversation
…body shortcuts drop below the functrace gate (rubash#825) `set -T; trap 'echo D:$BASH_COMMAND' DEBUG; x=$(true)` printed got=: the false/true/:: status shortcuts in expand_command_substitution_inner sat ABOVE the functrace+DEBUG disqualification gate, so the hardcoded empty output never entered the substitution child and GNU's inherited-DEBUG face was lost entirely (vendored bash trap.c:1466-1474 reset_or_restore_signal_handlers clears DEBUG/RETURN in the comsub child only when function_trace_mode == 0; subst.c:7143 command_substitute routes every body through parse_and_execute; execute_cmd.c:4648-4649 fires the head line for true/false/: too). Move both shortcuts below the gate — the same disqualification shape they already carried for xtrace (rubash#254). WSL GNU 5.3.0(1) stdin oracle, 8 forms byte-identical: x=$(true) -> got=D:true; x=$(false) -> got=[D:false] rc=1; $( (true) ) -> got2=[D:true]; $(true; true) fires twice into the capture; functrace-off / DEBUG-without--T / -T-without- trap controls keep their exact prior behavior (the issue's functrace-off face and the rubash#345 armed-inside face stay green). Audit probe debug-into-comsub-functrace-on green: the #713 nested- context harness goes 4 known divergences -> 3 (only the #826 probes remain, their semantics closed separately). Known pre-existing cosmetic divergence left untouched: for a top-level assignment whose body is $( ( … ) ) or $(< …), rubash's BASH_COMMAND printer re-renders the text (y=$(( true )) vs GNU's y=$( ( true ))). The fire set and captured substitution output are byte-identical. Regression: tests/issue825_comsub_debug_functrace_regressions.rs (8 cases, one per form).
…h the fd table, emitted once (rubash#826)
Three faces, one mechanism: the brace wrapper's open-failure report
bypassed the fd table the command established.
- { :; } 2>err2.txt > /nonexistent/f printed the diagnostic TWICE on
the real stderr and never created err2.txt: the stdio arms applied in
FIELD order (redirect_out before redirect_err) so the fd-1 open failed
before fd 2 was bound, and the swallowed IoError fell through to a
re-dispatch that failed and printed again (faces 1-2).
- ( { :; } > /nonexistent/f ) 2>err.txt captured AND leaked: the
wrapper's raw eprintln! bypassed the child's bound fd 2 (face 3).
GNU (vendored redir.c:767-955 do_redirection_internal applies the
redirect list in parse order; redir.c:135 redirection_error reports
through the fd 2 binding in force): one diagnostic, in the redirected
target.
- apply_brace_group_redirects: the four stdio arms run in PARSE order
(positions resolved against command.redirects). The 2>/2>> file arms
register their target as the FAILURE-REPORT destination instead of
binding fd_table[2]: a standing binding would be seen by the walker's
downstream 1>&2 dup, which GNU resolves against the fd 2 in force at
the DUP's own parse position (issue699 R1.1 { … } 1>&2 2>g regressed
under the standing-bind variant and is green again here). On a failed
open the diagnostic is written exactly once — into the established
target (fresh append-mode open; the arm's create did the single
O_TRUNC, append keeps the message at EOF like GNU's shared open file
description) or, with none established, through the executor's
fd-table fd-2 endpoint (write_default_stderr), which inside a
subshell resolves to the child's own 2> binding (face 3).
- open_compound_output_redirects_inner: an fd-2 FILE binding opens its
handle in append mode (fd 1 unchanged) — the wrapper's reports now
route through that binding, so writes must stay at EOF instead of
overwriting the file head after body writes.
- execute_brace_group_pipeline: the splice failure is adjudicated once
at finish_brace_redirect_failure (status 1, ERR trap once, errexit
promotion, and-or RHS skip) and the command is NOT re-dispatched.
WSL GNU 5.3.0(1) stdin oracle, byte-identical: the three ticket faces,
ERR single fire, errexit termination, 2>> capture, 2>/dev/null silence
(plain and subshell), nested-brace capture, body-not-run, and-or RHS
skip. Audit probes compound-redirect-fail-status / brace-redirect-err-
route / subshell-redirect-diag-route: semantics green (the remaining
harness delta is the $0 script-name namespace rendering /d/ vs /mnt/d/,
an environment artifact present on the base too).
Full cargo test --no-fail-fast failure profile is identical suite-by-
suite and count-by-count to the base commit (37 pre-existing failures
in 9 environment suites on both sides; zero regressed, zero missing;
issue699 7/7 and issue726 9/9 stay green).
Regression: tests/issue826_compound_redirect_diag_route_regressions.rs
(12 cases, one per form).
Member
Author
独立代码评审:APPROVE-WITH-NITS(无 BLOCKER,无需改码;两条 NIT 级备注见文末)独立评审树 #825(3daa7fc2)—— 实现代理对票面假设的反驳成立
#826(5daa47c4)—— 重设计裁定成立,常驻 fd_table[2] 的否决有据
纪律与回归
NIT(不阻塞,无需按此改码)
|
# Conflicts: # CHANGELOG.md
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 #825, closes #826. Two commits, one per ticket, both audited findings from the #713 nested-context second pass — recorded findings implemented as fixes, not blind patches.
Based on master `992d5c5e` (#831 and #811 already merged). Rebased on fetch at PR time; not merged from my side.
Commit 1 — #825: `set -T` DEBUG trap fires inside $( )
Root cause. The ticket hypothesized a missing functrace-scoped reset variant on the comsub copy path; the operative defect is one layer up: the `false`/`true`/`:` trivial-body status shortcuts in `expand_command_substitution_inner` (src/executor/command_substitution.rs) sat above the functrace+DEBUG disqualification gate, so `x=$(true)` took the hardcoded empty-output short circuit, never entered the substitution child, and GNU's inherited-DEBUG face was lost. (The functrace-scoped reset the ticket pointed at already exists in `reset_for_subshell_inner` and works.) Vendored anchors: bash trap.c:1466-1474 (`reset_or_restore_signal_handlers` clears DEBUG/RETURN in the comsub child only when `function_trace_mode == 0`), subst.c:7143 (`command_substitute` → `parse_and_execute`), execute_cmd.c:4648-4649 (head line for `true`/`false`/`:` too).
Fix. Both shortcuts move below the gate — the same disqualification shape they already carried for xtrace (rubash#254).
GNU differential (WSL GNU bash 5.3.0(1), stdin oracle, byte-exact):
Pre-existing cosmetic divergence left untouched (same on base): rubash's BASH_COMMAND printer re-renders `y=$( ( true ))` as `y=$(( true ))` for the top-level fire; fire set and capture are byte-identical.
Audit probe `debug-into-comsub-functrace-on` green — harness goes 4 known divergences → 3.
Commit 2 — #826: compound's own redirect-failure diagnostic via the fd table, emitted once
Root cause. Exit status was always correct (1); the diagnostic had three faces sharing one mechanism: the brace wrapper's open-failure report bypassed the fd table the command established.
GNU anchors (vendored): redir.c:767-955 `do_redirection_internal` applies the redirect list in parse order; redir.c:135 `redirection_error` reports through the fd 2 binding in force.
Fix (fix the reader, per the ticket's suggested direction):
GNU differential (WSL GNU bash 5.3.0(1), stdin oracle, byte-exact):
Remaining audit-harness delta on the three #826 probes: the diagnostic prolog's script-name namespace rendering (`/d/repo/…` for the Windows binary vs `/mnt/d/repo/…` for WSL GNU) — an environment artifact, present identically on the base; capture destination, single emission and rc are byte-identical.
#831 coordination (per the review rounds)
Verification