Skip to content

fix(procsub): >(exit N) ends only the substitution child - #1267

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1219-procsub-write-exit-child-local
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1219-procsub-write-exit-child-local

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1219

GNU subst.c:6362 process_substitute() forks the write-side >(...) body; the child ends through exit(rc) (subst.c:6628-6629) after restore_original_signals (subst.c:6421) cancels the parent's traps. Rubash ran the body inline on the parent executor and propagated the exit builtin's ExitCode, killing the shell with status N.

execute_output_process_substitution now scopes the trap table (snapshot + reset_for_subshell + restore), snapshots the parent's $? for the run, and absorbs the body's result into the status registered for wait $!.

Before:

$ rubash repro.sh        # echo hi > >(exit 3); echo rc=$?; echo done
(nothing; shell exits 3)

After (== GNU 5.3.20):

rc=0
done

trap 'echo T' EXIT; echo hi > >(exit 3) now prints T once at real exit (GNU parity; previously fired mid-run inside the body).

Test plan

  • cargo test --test issue1219_procsub_write_exit — 4 tests green
  • cargo fmt --check clean

Generated with Devin

…hell

GNU subst.c:6362 process_substitute() forks the write-side `>(...)` body;
the child ends through `exit(rc)` (subst.c:6628-6629) after
restore_original_signals (subst.c:6421) cancels the parent's traps.
Rubash ran the body inline on the parent executor and propagated the
`exit` builtin's ExitCode error, killing the shell with status N.

execute_output_process_substitution now scopes the trap table
(snapshot + reset_for_subshell + restore), snapshots the parent's $? for
the run, and absorbs the body's result into the status registered for
`wait $!` instead of returning it.

Verified vs WSL GNU Bash 5.3.20 (script-file probes):
  echo hi > >(exit 3); echo rc=$?; echo done   -> rc=0 / done (was: shell died, rc=3)
  trap 'echo T' EXIT; echo hi > >(exit 3)      -> T once (was: T fired in body)

Generated with [Devin](https://devin.ai)
@caomengxuan666
caomengxuan666 merged commit 58a5aec into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1219-procsub-write-exit-child-local branch October 23, 2026 08:54
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.

[bug] exit N in >(...) write-side procsub terminates the shell (GNU: ignored, rc=0)

2 participants