Skip to content

Commit

Permalink
chore: Review comments
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Mar 30, 2024
1 parent 7429d55 commit 516c01b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
24 changes: 10 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ impl Reaper {
.expect("cannot spawn async-process thread");
}

/// Reap zombie processes forever.
async fn reap(&'static self, driver_guard: reaper::Lock) -> ! {
self.sys.reap(driver_guard).await
}

/// Register a process with this reaper.
fn register(&'static self, child: std::process::Child) -> io::Result<reaper::ChildGuard> {
self.ensure_driven();
Expand Down Expand Up @@ -717,16 +712,9 @@ impl TryFrom<ChildStderr> for OwnedFd {
/// }).await;
/// # });
/// ```
#[allow(clippy::manual_async_fn)]
#[inline]
pub fn driver() -> impl Future<Output = Infallible> + Send + 'static {
struct CallOnDrop<F: FnMut()>(F);

impl<F: FnMut()> Drop for CallOnDrop<F> {
fn drop(&mut self) {
(self.0)();
}
}

async {
// Get the reaper.
let reaper = Reaper::get();
Expand All @@ -749,7 +737,7 @@ pub fn driver() -> impl Future<Output = Infallible> + Send + 'static {

// Acquire the reaper lock and start polling the SIGCHLD event.
let guard = reaper.sys.lock().await;
reaper.reap(guard).await
reaper.sys.reap(guard).await
}
}

Expand Down Expand Up @@ -1147,6 +1135,14 @@ fn blocking_fd(fd: rustix::fd::BorrowedFd<'_>) -> io::Result<()> {
Ok(())
}

struct CallOnDrop<F: FnMut()>(F);

impl<F: FnMut()> Drop for CallOnDrop<F> {
fn drop(&mut self) {
(self.0)();
}
}

#[cfg(test)]
mod test {
#[test]
Expand Down
12 changes: 2 additions & 10 deletions src/reaper/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ impl ChildGuard {

/// Begin the reaping process for this child.
pub(crate) fn reap(&mut self, reaper: &'static Reaper) {
struct CallOnDrop<F: FnMut()>(F);

impl<F: FnMut()> Drop for CallOnDrop<F> {
fn drop(&mut self) {
(self.0)();
}
}

// Create a future for polling this child.
let future = {
let mut inner = self.inner.take().unwrap();
Expand All @@ -113,14 +105,14 @@ impl ChildGuard {
reaper.zombies.fetch_add(1, Ordering::Relaxed);

// Decrement the zombie count once we are done.
let _guard = CallOnDrop(|| {
let _guard = crate::CallOnDrop(|| {
reaper.zombies.fetch_sub(1, Ordering::SeqCst);
});

// Wait on this child forever.
let result = future::poll_fn(|cx| inner.poll_wait(cx)).await;
if let Err(e) = result {
tracing::error!("error while polling zombie process: {}", e);
tracing::error!("error while polling zombie process: {}", e);
}
}
};
Expand Down

0 comments on commit 516c01b

Please sign in to comment.