Skip to content

Commit

Permalink
And stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Nov 11, 2023
1 parent dca3639 commit 07ff249
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Next (YYYY-MM-DD)

- Change `UnixChildExt::signal` to take `&self` instead of `&mut self`.
- Tokio grouped child `wait`s using Tokio's `Child::wait` and `::try_wait` in addition to the internal pgid-based logic, to help with cancellation.
- Grouped child `wait`s using upstream `::wait` and `::try_wait` in addition to the internal pgid-based logic, to help with cancellation.

## v4.1.0 (2023-11-05)

Expand Down
23 changes: 13 additions & 10 deletions src/stdlib/child/unix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
convert::TryInto,
io::{Error, ErrorKind, Read, Result},
io::{Error, Read, Result},
os::{
fd::BorrowedFd,
unix::{
Expand Down Expand Up @@ -117,18 +117,21 @@ impl ChildImp {
}

pub fn wait(&mut self) -> Result<ExitStatus> {
self.wait_imp(WaitPidFlag::empty())
.transpose()
.unwrap_or_else(|| {
Err(Error::new(
ErrorKind::Other,
"blocking waitpid returned pid=0",
))
})
if let Some(status) = self.try_wait()? {
return Ok(status);
}

match self.wait_imp(WaitPidFlag::empty()).transpose() {
None => self.inner.wait(),
Some(status) => status,
}
}

pub fn try_wait(&mut self) -> Result<Option<ExitStatus>> {
self.wait_imp(WaitPidFlag::WNOHANG)
match self.wait_imp(WaitPidFlag::WNOHANG) {
Ok(None) => self.inner.try_wait(),
otherwise => otherwise,
}
}

pub(super) fn read_both(
Expand Down

0 comments on commit 07ff249

Please sign in to comment.