Fix wait_with_pipe() so it waits for last child and uses exit status #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
unlike all of the other wait methods in FunChildren and CmdChildren, wait_with_pipe() does not actually wait for the last child in the pipeline to exit. it kills the last child when the provided function returns, and ignores that child’s exit status. killing the last child is potentially useful, to avoid deadlock if the caller fails to fully read stdout, but ignoring the last child’s exit status seems like a bug.
this patch fixes that bug by making wait_with_pipe() wait for the last child and use its exit status. if the child can’t exit because it has unread output, we automatically read and discard that output and wait again, until the child exits.
this is a breaking change for two reasons:
f
now takes a&mut Box<dyn Read>
, not aBox<dyn Read>
— though depending on the code provided inf
, this may only result in a new#[warn(unused_mut)]
warningyes
orsh -c "yes >&2 &"
now indefinitely block the return of wait_with_pipe() — though this is consistent with the behaviour of all the other wait methods