Repository navigation
fix(jobs): real-pid procsub placeholders + true procsub line numbers - #1122
Merged
Merged
Conversation
…rs (rubash#1022, rubash#1024) #1022: `$!` after a process substitution was a synthetic pid (shell_pid + 2^30 + seq), so `kill -0 $!` failed with ESRCH while GNU reports the forked child's real pid. GNU subst.c:6362 process_substitute runs make_child(NULL, FORK_ASYNC|FORK_PROCSUB) (jobs.c:2265+ sets last_asynchronous_pid/last_made_pid to the real fork pid), and $!/wait track that child (jobs.c procsub_add/procsub_waitpid, wait.def). Rubash runs substitution bodies inline with no child to signal, so register_process_substitution_status now forks a placeholder child that exits at once with the recorded status (unix; the previous synthetic pid stays as the non-unix/fork-failure fallback). The placeholder is born a zombie: `kill -0` and signal delivery behave exactly like GNU's just-exited procsub, while the recorded status stays the source of truth for `wait` (bgpids parity, repeat waits included). New JobTable.procsub_placeholders tracks signallable-but-unreaped pids: explicit/bare `wait` reaps them, `kill -0` no longer mistakes them for dead jobs, bare `wait -n` reports them (jobs.c wait_for_any_job scans procsubs after jobs), and input-form placeholders are reaped at registration (GNU's handler reaps a finished input procsub during the outer command). Persistent `>(...)` forms register the placeholder at open (pending) and complete it with the body status at close, so `exec > >(tee log); kill $TEED` reaches a real pid. #1024: a write-error diagnostic inside a procsub body was always `line 1` while GNU reports the true line. Two stacked causes: (1) the parser rebuilt the body source joining physical newlines with `;`, so every body command parsed on line 1 (GNU parse.y:4451+4632 keeps the body verbatim with its own newlines); (2) the inline body re-parsed from line 1 while GNU's forked child inherits line_number and parse_and_execute without SEVAL_RESETLINE (builtins/evalstring.c:315) numbers the body from the enclosing command's line. Fix: emit newline for bare mid-body newlines when rebuilding the source (explicit `;` spellings untouched), and parse inline bodies seeded from __RUBASH_CURRENT_LINE through the existing comsub canonical layout (normalize_comsub_body_statement_lines), which matches GNU's rules (bare newline advances, `;`-join shares, blank runs collapse). Scope notes: `>(...)`-body failure still fails the outer command and `>(exit N)` still aborts the script (pre-existing #699-adjacent status routing, untouched); `wait` on a still-open persistent `>(...)` reports 127 instead of blocking (no unkillable hang); `kill -TERM` on an already-finished inline body reports the recorded status, not 143 (the body can never be mid-flight in the inline model); post-`wait` multi-procsub bare `wait -n` may report the next status where GNU's prune race reports 127 (documented). Probes (bash 5.3.20 vs rubash, script-file, stderr): issue repros plus input/output/persistent forms, multi-line bodies, leading/blank-line and `;'`-newline edges, kill variants, double/repeat wait, `wait -p`, bare wait/ wait -n, jobs/disown/kill-% errors - all byte-identical modulo pids. cargo test --lib green (693); procsub/background/write-error integration files green (issue438 argv_word_stays_gnu_dev_fd_form and issue866 w1 fail identically on the unmodified binary - pre-existing/environmental).
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 #1022, closes #1024. (1) Procsub $! was synthetic (pid+2^30), always kill-dead: now fork a real immediately-exiting placeholder zombie per procsub (signallable like GNU's just-exited procsub), recorded in JobTable.procsub_placeholders; explicit/bare wait reaps, kill -0 skips the completed check for members; input forms reaped at once, output forms outlive the command, persistent >( ) pending-on-open/status-on-close. (2) Procsub bodies were newline-flattened to ; and renumbered from 1: keep bare newlines in source rebuild, parse via canonical comsub layout seeded at CURRENT_LINE, so write-error diagnostics carry the true line (GNU parse.y:4451+evalstring.c:315). Untested-shape guardrails documented in code (no mid-flight TERM 143, no pending-persistent wait block, no multi-bare-wait-n prune). Tests: lib 693 + procsub/bg/write-error suites green, executor_tests delta-free vs baseline; GNU parity byte-identical except pid values.