mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-31 00:00:07 +02:00
process: Implement a queue for repeatedly attempting to reap orphaned processes
This commit is contained in:
@@ -25,6 +25,7 @@ extern crate libc;
|
||||
extern crate mio;
|
||||
extern crate tokio_signal;
|
||||
|
||||
mod orphan;
|
||||
mod reap;
|
||||
|
||||
use futures::future::FlattenStream;
|
||||
@@ -32,6 +33,8 @@ use futures::{Future, Poll};
|
||||
use self::mio::{Poll as MioPoll, PollOpt, Ready, Token};
|
||||
use self::mio::unix::{EventedFd, UnixReady};
|
||||
use self::mio::event::Evented;
|
||||
use self::orphan::{AtomicOrphanQueue, OrphanQueue, Wait};
|
||||
use self::reap::{Kill, Reaper};
|
||||
use self::tokio_signal::unix::Signal;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
@@ -42,6 +45,10 @@ use tokio_io::IoFuture;
|
||||
use tokio_reactor::{Handle, PollEvented};
|
||||
|
||||
impl Wait for process::Child {
|
||||
fn id(&self) -> u32 {
|
||||
self.id()
|
||||
}
|
||||
|
||||
fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
|
||||
self.try_wait()
|
||||
}
|
||||
@@ -53,6 +60,28 @@ impl Kill for process::Child {
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref ORPHAN_QUEUE: AtomicOrphanQueue<process::Child> = AtomicOrphanQueue::new();
|
||||
}
|
||||
|
||||
struct GlobalOrphanQueue;
|
||||
|
||||
impl fmt::Debug for GlobalOrphanQueue {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
ORPHAN_QUEUE.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl OrphanQueue<process::Child> for GlobalOrphanQueue {
|
||||
fn push_orphan(&self, orphan: process::Child) {
|
||||
ORPHAN_QUEUE.push_orphan(orphan)
|
||||
}
|
||||
|
||||
fn reap_orphans(&self) {
|
||||
ORPHAN_QUEUE.reap_orphans()
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
pub struct Child {
|
||||
inner: Reaper<process::Child, FlattenStream<IoFuture<Signal>>>,
|
||||
|
||||
Reference in New Issue
Block a user