Skip to content

fix(function): preserve call-site file stdin across child spawn - #653

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/647-function-redirect-stdin
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/647-function-redirect-stdin

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes #647. Ordinary file redirects at a function call site now stay on the real fd-table file descriptor instead of being slurped into the FUNCTION_STDIN text mirror. External children inherit the open file description and shared file offset, so later shell reads continue from the correct line.

Validation

  • cargo fmt --all -- --check passed.
  • cargo build --locked passed.
  • cargo test --test issue647_function_redirect_stdin_regressions --locked passed: 2/2.
  • GNU Bash 5.3 WSL comparison passed for the four-line loop and the post-spawn read case.
  • cargo test --workspace --locked reached the existing cli_tests suite but remained red on 15 unrelated baseline/environment failures, including missing pwsh, example working-directory failures, and tilde-home environment assumptions; the [P1] function call-site redirect + external command: redirected stdin is lost after the child spawn (read returns EOF) #647 regression test passed.

References

  • GNU execute_cmd.c function execution applies the call redirect around the function body.
  • GNU redir.c preserves the inherited open file description and shared offset across child spawn.

GNU execute_cmd.c execute_function applies the call redirect around the body and redir.c do_redirections inherits the open file description and shared offset. Keep ordinary function call-site files in FdTable instead of slurping them into FUNCTION_STDIN.
@caomengxuan666
caomengxuan666 merged commit 96488f4 into master Oct 16, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/647-function-redirect-stdin branch October 16, 2026 08:49
caomengxuan666 added a commit that referenced this pull request Oct 16, 2026
PR #653 flipped precedence: f() { cat; } < deffile; f < callfile
printed call; GNU prints definition (call-site outer, definition
inner per execute_cmd.c:5205). The (None, _, binding) arm installed
the live fd 0 then fell through to the call-site file, overwriting it.

Keep a live definition fd-0 binding; skip call-site stdin then.
part_054 14/14.
caomengxuan666 added a commit that referenced this pull request Oct 16, 2026
PR #653 flipped precedence: f() { cat; } < deffile; f < callfile
printed call; GNU prints definition (call-site outer, definition
inner per execute_cmd.c:5205). The (None, _, binding) arm installed
the live fd 0 then fell through to the call-site file, overwriting it.

Keep a live definition fd-0 binding; skip call-site stdin then.
part_054 14/14.

Co-authored-by: caomengxuan666 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] function call-site redirect + external command: redirected stdin is lost after the child spawn (read returns EOF)

1 participant