Repository navigation
followup-a: PATH bind flushes command hash (#1551) + ambient 2>&1 pipeline stderr (#1552) - #1572
Merged
Merged
Conversation
… — variables.c sv_path -> phash_flush (#1551) GNU registers an assignment function for PATH in the special_vars table (variables.c:5819 { "PATH", sv_path }) whose whole body is phash_flush() (variables.c:5919 -> hashcmd.c:57): any bind or unbind of PATH empties the remembered command locations, even a same-value bind, while attribute-only operations (export PATH, declare -p PATH) never bind and keep the table. rubash never fired it: `hash -p` entries survived PATH assignments and kept executing, `hash` showed stale entries with bumped hit counts, and `unset PATH` left the table populated. - builtins::hash::flush_command_hash_table clears the state's __RUBASH_HASH_TABLE plus the lookup cache's hashed mirror (path::flush_command_lookup_cache_hashed); the fingerprint-keyed scan stores stay self-invalidating. The path.rs comment claiming a PATH change does not flush is corrected (that reading came from #1137's initialization scenario, not from assignment). - The flush fires at every bind funnel, mirroring the #1531 sv_locale discipline: the executor assignment funnel (plain/+=/temp-prefix/ read/for/select/getopts), declare/typeset/local operands (with and without a value), export/readonly value binds (has_assign-gated — their name-only forms materialize the current value for the mirror but do not bind in GNU), unset, the temp-assignment and function-local restore paths (a restore is a re-bind), printf -v, and the arithmetic bind points. - set_command_lookup_cache now writes ONLY the hashed mirror: its copy into the fingerprint-keyed `results` memo was not scan evidence and resurrected flushed entries whenever the fingerprint later coincided. - Fork brackets for the process-global mirror (RAII path::hashed_cache_fork_guard, same shape as the SIGPIPE guard): pipeline elements, command substitution (both the &self wrapper and the &mut typed dispatcher), ( ) subshells, and input process substitutions are GNU forks (execute_cmd.c:2620, subst.c:7143, execute_cmd.c:1576, subst.c:6362) — a child's PATH-bind flush or `hash -p` write must not reach the parent's table. Regression pins: tests/issue1551_path_assignment_hash_flush_regressions.rs (14), and the #1545 file's previously-ignored sv_path pin is activated (its GNU expectations were already written).
…output stream, not the next stage's stdin (#1552) Filed as: a timed pipeline whose first stage is a dash word loses its `command not found` diagnostic (`time '-p' true | cat` under a bad PATH reported only `cat:`). The bare form never reproduced — the parsetime2 comparison harness wraps cases in `( eval ... ) 2>&1`, and the enclosing `2>&1` is the real trigger. GNU binds a pipeline element's fd 2 to the fd-1 object the pipeline INHERITED (the enclosing stream): execute_cmd.c:2620 execute_pipeline connects the elements with fresh pipes first, and an ambient `2>&1` (enclosing compound, brace group, subshell, function, or `exec`) dups onto that inherited object, never onto the inter-stage pipe. rubash's sequential pipeline driver folded every stage's captured stderr into next_input whenever fd 2 resolved to Stdout, so a non-final stage's diagnostic became the next stage's stdin and died unread — dash words and ordinary names alike, timed or not (`{ nosuchA | nosuchB | nosuchC; } 2>&1` showed only the last). The final stage was accidentally right: its next_input IS the pipeline output. The concurrent-prefix recovery merge in the same function had the same flaw. Fix: under an ambient binding, non-final stages accumulate their stderr in stage order and it is written with the pipeline's output (preceding the final stage's contribution, matching GNU's concurrent starts); the concurrent prefix's captured stderr takes the same route instead of the pipe payload (its bytes also leave the input_timing payload length, which now measures only real payload). A stage's OWN `2>&1`/`|&` is untouched — those bytes are resolved against the pipe-bound fd 1 by route_pipeline_stage_streams before this merge and arrive already folded. Regression pins: tests/issue1552_ambient_stderr_pipeline_diagnostic_regressions.rs (8) — both filed forms, ordinary-name timed first stage, three-stage ordering, external-prefix middle stage, the comsub `2>&1` capture idiom, and the no-redirect / stage-own-dup controls.
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.
followup-a slice: two fixes, one commit per issue, cherry-picked onto master
a4c6c2adwith zero conflicts (diff stats identical to the cluster branch).#1551 — PATH assignment flushes the command hash table (sv_path)
GNU
variables.c:5919sv_path()is exactlyphash_flush(): any bind or unbind of PATH flushes the whole hashed-command table (same-value assignment and+=included; pure attribute operations likeexport PATH/readonly PATHwith no value do not). rubash kept two stores (the__RUBASH_HASH_TABLEenv key and the process-global lookup cache'shashedmirror) and flushed neither, so stale entries kept being served afterPATH=...,unset PATH, etc.The fix hangs a
name == "PATH"gate on every binding funnel (assignment funnel incl. temp-prefix bind and restore, declare/typeset/local operands, setattr with-value binds, unset,printf -v, arithmetic binds, read/for/select binds) via a newbuiltins::hash::flush_command_hash_table+path::flush_command_lookup_cache_hashed. Two same-family defects found by the probe matrix are fixed in the same commit:resultsmemo, so a flushed entry could resurrect on a fingerprint coincidence; the setter now writes only the hashed mirror.&selfand&mutdispatch entries —( )subshells, input-form procsub). A new RAIIhashed_cache_fork_guard(snapshot/restore, same discipline as the sigpipe guard) now covers all of them; the lastpipe final stage is deliberately unguarded (it runs in the current shell).Regression:
tests/issue1551_path_assignment_hash_flush_regressions.rs(14 tests), plus the#[ignore]d pin in the issue1545 file is activated (13/13 there).Fixes #1551
#1552 — non-final pipeline stage diagnostics lost under an ambient
2>&1Root cause differs from the issue's original hypothesis. The bare timed form does not reproduce; the actual trigger is an ambient (environmental)
2>&1binding around the pipeline (a compound command / group / exec redirecting stderr onto the inherited stdout). It is not limited to dash words and not limited to timed pipelines:{ nosuchA | nosuchB | nosuchC; } 2>&1lost every non-final stage's diagnostic.GNU (
execute_cmd.c:2620) binds each stage's fd 2 to the inherited fd-1 object, never to the inter-stage pipe. rubash's sequential pipeline driver unconditionally folded each stage's captured stderr intonext_inputwhenever fd 2 wasStdout, so a non-final stage's diagnostic became the next stage's unread stdin. The fix accumulates non-final stage stderr in stage order (ambient_stderr) and writes it into the pipeline output stream after the loop; the concurrent external-prefix path gets the same treatment. A stage's own2>&1/|&is unaffected (already folded into the pipe payload before the merge point).Regression:
tests/issue1552_ambient_stderr_pipeline_diagnostic_regressions.rs(8 tests).Fixes #1552
Out of scope
Residual R3 — a pipeline last stage's own
2>fileloses its command-not-found diagnostic entirely (neither on the stream nor in the file; pre-existing, unrelated mechanism) — is filed separately as #1571 and is not closed by this PR.Verification on the integrated tree (gated build, purified environment) is reported in the slice report; local full verification is the merge gate per campaign policy.