Skip to content

Document Errno::ECHILD when something else reaps the command - #36

Merged
orien merged 1 commit into
mainfrom
document-echild
Nov 29, 2026
Merged

orien merged 1 commit into
mainfrom
document-echild

Conversation

@orien

@orien orien commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Context

If something else in the process reaps the command before SafeShell does, such as a trap("CHLD") handler that waits on children, or the kernel when CHLD is ignored, the wait after the read raises Errno::ECHILD and the command's output is discarded. The docs say a SystemCallError means the program could not be started, and that every method sets $?, so a caller reads this as the command not having run and trusts a $? that describes another command.

PE-8869

Change

Documents the raise in its own @raise tag on execute and in the README:

  • The command ran, but the output it would have returned and its status are lost; a stream redirected to a file is still written.
  • $? is not set: it is nil, unchanged from the previous command, or whatever the other waiter reaped. The module doc and the README's $? sentence are qualified to match.
  • An example ignores CHLD and checks, for each of the three methods, that it raises after the command has run and leaves $? unchanged.

Considerations

  • The behaviour is unchanged. Once another waiter has the status it cannot be recovered, so execute? and execute! cannot answer their question.
  • The example runs on CRuby only: on TruffleRuby an ignored CHLD does not make the kernel reap its children, so nothing raises.

@orien orien changed the title Document Errno::ECHILD when something else reaps the command Document Errno::ECHILD when something else reaps the command Nov 29, 2026
If something else in the process reaps the command first, as a CHLD
trap handler that waits on children does, or the kernel when CHLD is
ignored, the wait after the read raises Errno::ECHILD and the output
is lost. The documentation said a SystemCallError means the program
could not start, so a caller would read it as the command not having
run, and said every method sets $?.

The status cannot be recovered once another waiter has it, so execute?
and execute! cannot answer their question. Keep the raise, and document
it in its own @raise tag and in the README: the command ran, the output
it would have returned and its status are lost, a stream redirected to
a file is still written, and $? is not set. Qualify the two places that
say every method sets $?.

The example ignores CHLD, which makes the kernel reap children at once.
TruffleRuby does not pass that on to its children, so the example runs
on CRuby only.
@orien
orien marked this pull request as ready for review November 29, 2026 14:54
@orien
orien merged commit e200cec into main Nov 29, 2026
16 checks passed
@orien
orien deleted the document-echild branch November 29, 2026 14: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.

1 participant