Skip to content

fix(jobs): real-pid procsub placeholders + true procsub line numbers - #1122

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/job-diag
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/job-diag

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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.

…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).
@caomengxuan666
caomengxuan666 merged commit b8d2331 into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/job-diag 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] Background-job write-error diagnostic always attributed to line 1 [bug] `` after process substitution is an encoded pid, unusable with signals

1 participant