On this page

0056. Subprocess v0

Context

CLI tools need child processes without ambient authority or implicit shell parsing. Capturing one pipe before the other can deadlock on large output.

Decision

Expose only Process.run(str, vec<str>) -> result<Output, CliError> and Process.stream(str, vec<str>) -> result<i64, CliError> through cli.process. Seed Output { status: i64, stdout: bytes, stderr: bytes }. Use posix_spawnp with PATH lookup and locally declared environ, never a shell. Capture uses /dev/null stdin and polls both output pipes until EOF, allocating raw bytes in the caller's region. Internal descriptors are close-on-exec and above stdio; file capabilities must also use O_CLOEXEC when implemented. Stream flushes stdout first, then inherits stdin/stdout/stderr. Wait retries EINTR; normal status is the exit code, signalled status is 128 plus the signal. The interpreter uses std::process::Command, wait_with_output for capture, inherited stdio for stream, and flushes Host.out before streaming.

Review refinement: children start with default SIGPIPE, even when the parent inherited SIG_IGN. C uses posix_spawnattr_setsigdefault with SIGPIPE and POSIX_SPAWN_SETSIGDEF, matching Rust Command. Inheriting ignored SIGPIPE would make native and interpreter child behavior disagree. Capture allocation failures (including overflow, reservation, commit and budget exhaustion) close the pipes, kill and reap the owned child before reporting the OOM trap.

Platform operations return a raw status record; shared lowering constructs the language result and error text. ENOENT becomes NotFound("no such program: x"), EACCES becomes Denied("permission denied: x"), other failures become Io("spawn x: os error N"). Embedded NUL in command/arguments is EINVAL; empty arguments are preserved. Child nonzero status is success, not CliError. Output remains bytes, including NUL and invalid UTF-8. ProcessRun(layout) is Fresh; normal arena escape placement applies to captured output/error messages. E0910 teaches vec arguments; E0911 rejects literal program names containing spaces, teaching separate program/argument values. No other new codes.

Alternatives considered

Consequences

Only a passed Process capability grants subprocess access. Capture cannot read parent stdin and has no cross-pipe ordering guarantee. Stream inherits actual process descriptors; interpreter memory Hosts only supply the pre-spawn flush. Captured output is bounded by the arena budget, like other fresh allocations. No dependencies, Rust unsafe, or shell fallback are required.