use std::sync::{Arc, OnceLock};
use super::exit::Exit;
fn children() -> &'static kovan_map::HashMap<u32, Arc<Exit>> {
static CHILDREN: OnceLock<kovan_map::HashMap<u32, Arc<Exit>>> = OnceLock::new();
CHILDREN.get_or_init(|| kovan_map::HashMap::with_capacity(64))
}
pub(crate) fn watch(exit: &Arc<Exit>) {
if let Err(err) = crate::signal::unix::listen_raw(libc::SIGCHLD) {
exit.finish(Err(err.raw_os_error().unwrap_or(libc::EIO)));
return;
}
children().insert(exit.pid(), Arc::clone(exit));
crate::signal::unix::ensure_pump();
reap();
}
pub(crate) fn reap() {
for (pid, exit) in children().iter() {
if let Some(outcome) = exit.reap_by_pid() {
children().remove(&pid);
exit.finish(outcome);
}
}
}