Skip to content

spawn: deleted-cwd spawn anchor + comsub ambient fd delivery + procsub settlement completion pins (Refs #3198, Refs #3201, Refs #2526) - #3234

Merged
caomengxuan666 merged 9 commits into
masterfrom
fix/W-SPAWN-lifecycle
Nov 10, 2026
Merged

caomengxuan666 merged 9 commits into
masterfrom
fix/W-SPAWN-lifecycle

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

W-SPAWN lane: process-lifecycle family — spawn cwd stamping and comsub fd delivery, plus completion-form settlement pins.

#3198 — deleted cwd refused every external spawn (rc 127)

GNU: cd moves the process cwd itself (builtins/cd.def cd_builtin -> chdir) and execute_cmd.c execute_disk_command forks a child that inherits it; no path is re-resolved at spawn, so an unlinked cwd stays valid. Under G-02 the session cwd is a field and every spawn stamped it with Command::current_dir(path), whose child-side chdir re-resolves the string — ENOENT once the directory is gone.

Fix, by mechanism in one funnel: ShellState gains a cwd anchor (an open handle to the cwd directory, refreshed on cd and on each stamp, with a (dev, ino) freshness check). The new stamp_spawn_cwd replaces all 15 direct current_dir stamps (foreground, pipeline stages, compounds, comsub shortcut, procsub respawn, fallbacks): resolvable path → stamp by path as before; unresolvable but anchored → pre_exec fchdir onto the anchor inode (. is the deleted dir itself, .. its real parent); unanchored → leave unstamped rather than refuse the spawn. spawn_whitelisted (respawn face) likewise skips an unresolvable cwd stamp. Pins: tests/issue3198_deleted_cwd_spawn.rs, 7 completion-form cells (outputs + exit codes, no timing thresholds).

#3201 — comsub ambient fd delivery depended on body shape

Repeatability measured before fixing (N=20/10): a trivial comsub body delivered ambient fds 0/20; a non-trivial body 10/10. The split is path selection, not timing: the trivial-body shortcut spawner (run_external_command_substitution) registered no ambient pins, while the full executor delivers them. GNU subst.c:7143 command_substitute has one fork path for every body.

Fix: the shortcut spawner now registers the ambient pin set (ambient_fd_pins_unbound, sharing the ambient_fd_pins_for core) through the existing pin_ambient_fds_in_child transport. Sources are the fd table's own handles, so no inheritable duplicate — and no new alias — is introduced on this face. Pins: tests/issue3201_comsub_ambient_fd.rs, exact fd sets for the trivial face, presence-only for the full-executor/direct faces whose alias behaviour is a different issue's face.

#2526 — settlement membership, completion-form pins

Facecheck: the headline block was adjudicated in 2026-11 as a pin-harness artifact and the bare-wait membership cells already match GNU (see the existing settlement pins on master). This PR adds tests/issue2526_procsub_settlement_completion.rs: the same cells plus the abandoned-producer boundary, asserted only by output bytes, exit status, and marker-file existence at shell exit — no absolute time thresholds. GNU reference: jobs.c:2796 wait_for_background_pids, subst.c:6479 procsub_add. The Windows finish-time face stays with the Windows side per the earlier adjudication; nothing here claims it.

What this PR deletes

Nothing is deleted. It adds the cwd-anchor state and one spawn-stamp funnel (replacing 15 direct stamp call sites), adds ambient pin delivery to the comsub shortcut spawner, and adds three pin files. The ambient pin transport itself and the procsub spawn-fd face are untouched.

Refs #3198
Refs #3201
Refs #2526

@caomengxuan666 caomengxuan666 changed the title fix(spawn): deleted-cwd spawn anchor + comsub ambient fd delivery + procsub settlement completion pins (Refs #3198, Refs #3201, Refs #2526) spawn: deleted-cwd spawn anchor + comsub ambient fd delivery + procsub settlement completion pins (Refs #3198, Refs #3201, Refs #2526) Nov 10, 2026
…26 settlement markers at shell exit

Refs #3198, Refs #2526

Rework of the two captain-review points:

- The deleted-cwd anchor served spawned children (fchdir) but not
  in-process readers: the emulated cat resolved a relative operand
  through session_path's string join, so `cat ../f` from a deleted
  cwd died at the dead path component where a spawned cat reads it
  fine (discrimination probe: real wc/grep/head/dd all read `../f`
  from the deleted inode; only the emulated cat and cp failed).
  external_cat's operand read now goes through the new
  Executor::read_session_anchored: for a relative operand whose
  session cwd no longer resolves, the read opens relative to the
  cwd anchor handle (openat) - the in-process twin of
  stamp_spawn_cwd's fchdir, with the same two-mode rule. Absolute
  operands keep the plain path open, matching GNU's ENOENT for
  `cat $PWD/../f` from a deleted cwd.

- The 2526 settlement-completion pin asserted marker existence
  only after draining the shell's pipes to EOF; a detached
  producer inherits the stderr pipe and holds EOF off until it
  exits, so the assertions ran after the producer's marker touch
  and failed for any correct shell (GNU included). The harness now
  snapshots marker existence at shell exit, before either pipe is
  drained (pipes drain on side threads); values are the recorded
  GNU 5.3.20 oracle shapes.
@caomengxuan666
caomengxuan666 merged commit a78f0cd into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…3221)

The output process-substitution spawn carries fd>=3 through the __RUBASH_FD_* env channel as inheritable dups delivered AT their stamped numbers; the child's init restores the stamped handle instead of adopting whatever descriptor sits at slot fd. Without this declaration the consumer adopted the inherited outer file at slot 3 (direct-test6: tap.log 7 lines, comsub empty, INNER-RC=1). GNU anchor: subst.c:6362 process_substitute forks the consumer at expansion time inheriting the expansion-time table, which is what the stamped handle carries.

The comsub-nesting attribution half of this shape is already in master via #3132 (dollar_group_end opacity, d65441d): a span inside $(...) belongs to the comsub child, so the clone's stage machinery materializes it via this stamped spawn route. This commit carries the stamped-delivery half plus the pin that proves the combination.

Verified on the Simular box. run6 (pre-rebase tree): fail-first pin 3 passed / 2 failed (cells 04/05 red); head pin 5 passed / 0 failed; probe-adopt, V1, V2, V3 all pass; direct-test6 INNER-RC=0; RUSTFLAGS="-D warnings" cargo check rc=0; fmt rc=0; marker-lint rc=0; lib head 1207 passed / 0 failed, failure name set empty. run7 (rebased head, box pid 718998): Phase A on pure master d7a3725 — pin 5/0 and probe-adopt PASS without this PR (#3132 + #3234 already fix the reduced shapes); Phase B on the head — probe-adopt, V1, V2, V3 pass, pin 5/0, direct-test6 INNER-RC=0, -D warnings/fmt/marker-lint rc=0, lib head 1230 passed / 0 failed / 4 ignored, failure names none. run8 (discrimination, 917870f binary, box pid 721997): direct-test6 INNER-RC=1 with the byte-identical leak and pin 5/0 — #3266 exonerated, and the stamped insert is what fixes the real bats shape (the reduced pin passes on master without it; the full shape is guarded by the direct-test6 box leg). Adjacent gap, out of scope: the backquote shape (out=`exec 3<&1; ...`) still fails on the head (BQ-FAIL: log non-empty) — #3132's rule covers only $-groups; GNU expects OUT hello twice, log empty.

Refs #3221
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.

1 participant