No mark, ral’s fault
A spawn error is the program’s only if the child had already made its mark;
without the mark, one of ral’s own steps failed. The last pre-exec step of
every Unix spawn writes one byte on a close-on-exec socket
(spawn_with_pgid_after, core/src/process/group/unix.rs). The execve that
follows can then fail only as that image’s own failure, and std’s errno
already says which. If the image is a launcher, fork attributes that error
to it, never a later payload report’s error.
- The mark is one byte on a close-on-exec socketpair. The parent reads its
end without waiting (
attributed,recvwithDONTWAIT): the mark precedes theerrnothatstdhas already read, so a byte absent is a byte never written. With the mark, the error isSpawnError::Exec, henceUnstarted::Programatfork; launcher attribution happens before any report is heard. Without it,SpawnError::Prepare: the fork, the placement, apre_exechook of any caller, orstd’s own steps before them (a NUL in an argument). - The closure owns the socket. The pre-exec closure is
move, so the fd it writes is valid for as long as theCommandlives, whenever and however often it is run. Nothing it writes to can have been closed or reused behind it. - The mark is the last step. Hooks run in registration order, so the
launch’s own (its one
ChildSetuphook:2>&1, rlimits, the guest jail) precede the placement, the signal reset and the caller’safterhook, which precede the mark. A step added later than the mark would be blamed on the program. - On
detach, the grandchild writes the mark and the intermediate never does. The hook forks; the intermediate writes the grandchild’s pid and_exits inside the hook, short of the mark; the grandchild goes on to make it.Oktherefore proves the grandchild reached itsexecve, and a failure before it is ral’s.
Why. The alternative reads an errno for whose it is, and the same errno
means both: EPERM from setpgid into a group nobody leads is not
permission denied of a program. Blame by errno mislabels ral’s failures as
the program’s; blame by position cannot. The rule fixes the position of the
mark, and nothing else.
See ral-s-failure-is-never-the-programs and an-external-end-to-end.