Repository navigation
WIP: trap-visible $BASH_COMMAND/$BASH_SOURCE truth under compound redirects (#1872) - #1875
Merged
Merged
Conversation
…under compound redirects (#1872) Mechanism A — $BASH_COMMAND. GNU stamps a command with its OWN node text: print_cmd.c make_command_string prints the node's own redirection list, and execute_cmd.c:779 updates BASH_COMMAND from that text before running any traps. Rubash splices an enclosing compound's redirects into body element nodes (marked injected — support_names::injected_group_redirect, whose contract is "NOT the command's own redirect"); execution consumers honor the mark but the text renderers did not, so inside { ...; } >>f 2>>f the DEBUG trap reported `echo one >> f 2>> f`. bash_command_text and append_source_redirects (command_text.rs) now filter marked redirects through one funnel helper, restoring the invariant for every splice face (brace groups, case clauses, loops, function calls, source) at any depth, while an element's own redirects still render. Mechanism B — $BASH_SOURCE. GNU keeps one live dynamic array (variables.c:1892 init_dynamic_array_var get_self; execute_cmd.c:5313 push_source on function entry; evalfile push/pop for source): scalar reads, element reads and declare -p all observe the same stack. Rubash's env mirror cell refreshed only at source-frame push/pop while function entry/exit moved only the live stack, so scalar $BASH_SOURCE (the form bats' DEBUG trap passes) and declare -p froze at the last sourced file after any function call returned — bats then classified every test command as bats-internal and emitted empty failure stack traces. dynamic_parameter_value gains a BASH_SOURCE arm and dynamic_declaration_view gains BASH_SOURCE/BASH_LINENO arms rendering from the composed views element reads already use (the FUNCNAME/#1394 precedent); declare's listing mode merges the two views like PIPESTATUS. Regression: tests/issue1872_trap_visible_state_regressions.rs — 11 pins (group/function/source splice faces, ERR trap, scalar/ declare/listing reads, fd-4 bats geometry), all failing on master 1a4e86f, all passing here. Gates: lib 773/1/1 (baseline set), diffcorpus 306/306, trap/sig/#1844 adjacent targets green, -D warnings clean (lib+bins).
Member
Author
|
Gate evidence (local, tree at 4529dc9; baseline master 1a4e86f):
Full cluster report with root-cause analysis, GNU citations (execute_cmd.c:779, execute_cmd.c:5313, variables.c:1892, print_cmd.c make_command_string), the minimal BASH_SOURCE isolation ladder, and three REPORT-only residual observations: ~/workspace/issue-clearance/clusters/w3-trapstate/REPORT.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.
Fixes #1872
Refs #1720
What
Two invariant breaks in trap-visible state, one family — fixed at the invariants, no bats/group-shape special cases.
A. $BASH_COMMAND baked in an enclosing compound's redirects. GNU stamps a command with its OWN node text (print_cmd.c
make_command_stringprints the node's own redirection list; execute_cmd.c:779 updates BASH_COMMAND from that text before running traps). Rubash splices a compound's redirects into body element nodes — marked injected (support_names::injected_group_redirect, contract: "NOT the command's own redirect"). Execution consumers honor the mark; the text renderers did not, so inside{ …; } >>f 2>>fthe DEBUG trap reportedecho one >> f 2>> f.bash_command_textandappend_source_redirects(command_text.rs) now filter marked redirects through one funnel helper (own_redirect), covering every splice face (brace groups, case clauses, loops, function calls,source) at any depth; an element's own redirects still render.B. $BASH_SOURCE scalar/declare froze at the last sourced file. GNU keeps one live dynamic array (variables.c:1892
init_dynamic_array_varget_self; execute_cmd.c:5313push_sourceon function entry; evalfile push/pop for source) — scalar, element and declare reads observe the same stack. Rubash's env mirror cell refreshed only at source-frame push/pop while function entry/exit moved only the live stack, so after any function call returned, scalar$BASH_SOURCE(the form bats' DEBUG trap passes) anddeclare -preturned the frozen frame. bats classified every test command as bats-internal and its failure stack traces came out empty — the main root of the bats-core suite reds in #1720.dynamic_parameter_valuegains a BASH_SOURCE arm anddynamic_declaration_viewgains BASH_SOURCE/BASH_LINENO arms rendering from the composed views element reads already use (FUNCNAME/#1394 precedent); declare listing mode merges the two views like PIPESTATUS.Regression pins
tests/issue1872_trap_visible_state_regressions.rs— 11 pins: group simple/function elements, element-own-redirect preservation, ERR trap in group, function-call body stamps, source-face stamps, trap-argument ladder across a loader-sourced definition, scalar checkpoints, declare operand + listing forms, and the full fd-4 bats geometry. All 11 fail on master 1a4e86f, all 11 pass here (oracle: GNU bash 5.3.20, script files).Gates (local, this tree)
ownership_unary_operators_check_existing_file)exec— GNU bash does not run it #1012/[bug] EXIT trap dropped when function call is the whole comsubst body/pipeline stage #1104/[bug] return N in DEBUG trap aborts whole script with function calls (set -T) #1162/[bug] ERR trap dropped for unrescued failing comsubst under set -e #1171/[bug]break/continuein ERR-trap action silently ignored inside loops (GNU honors it) #1405/[bug]break/continuein function's RETURN trap leaks into the caller's loop (GNU errors) #1406/[bug] DEBUG trap under functrace: function call inside $() reports the outer command in $BASH_COMMAND and fires once instead of twice #1473/[bug] Async subshells and async builtins lose the inherited trap table (trap -p prints nothing) #1630/[bug] trap-ignore in subshell leaks SIG_IGN to parent: parent survives TERM it should die from #1654/[bug] Plain-path null command from comsub does not fire the ERR trap (timed form fixed in #1611) #1661), [fd] 重定向失败的 pipeline stage 状态漏入管线 $?(GNU 0 / rubash 1) #1844 redirect-failure pipeline, host_internal_trap_suppression, debugger_flag_gnu_parity-D warningsclean (lib+bins — the niu-CI surface); rustfmt applied to changed files; CR=0Cluster report: ~/workspace/issue-clearance/clusters/w3-trapstate/REPORT.md