From 07ff249c271d64c1ebc43dcfedec9058d8b1c04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 11 Nov 2023 23:39:16 +1300 Subject: [PATCH] And stdlib --- CHANGELOG.md | 2 +- src/stdlib/child/unix.rs | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index effefa1..77ba176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/stdlib/child/unix.rs b/src/stdlib/child/unix.rs index 2375e25..8eb8454 100644 --- a/src/stdlib/child/unix.rs +++ b/src/stdlib/child/unix.rs @@ -1,6 +1,6 @@ use std::{ convert::TryInto, - io::{Error, ErrorKind, Read, Result}, + io::{Error, Read, Result}, os::{ fd::BorrowedFd, unix::{ @@ -117,18 +117,21 @@ impl ChildImp { } pub fn wait(&mut self) -> Result { - 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> { - self.wait_imp(WaitPidFlag::WNOHANG) + match self.wait_imp(WaitPidFlag::WNOHANG) { + Ok(None) => self.inner.try_wait(), + otherwise => otherwise, + } } pub(super) fn read_both(