Skip to content

Commit dc94e5e

Browse files
authored
Merge pull request #39 from edera-dev/fix/reap-zombies
fix(supervisor): reap any leftover zombies when shutting down the container
2 parents 74c9114 + 9547009 commit dc94e5e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/wrap.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ fn set_process_limit(resource: RLimit, limit: Option<u64>) -> Result<()> {
5656
}
5757
}
5858

59+
fn reap_children() -> Result<()> {
60+
while unsafe { libc::waitpid(-1, ptr::null_mut(), libc::WNOHANG) } > 0 {}
61+
62+
Ok(())
63+
}
64+
5965
fn wait_for_pid(pid: libc::pid_t) -> Result<i32> {
6066
let status = unsafe {
6167
let mut st: MaybeUninit<i32> = MaybeUninit::uninit();
@@ -83,6 +89,8 @@ fn fork_and_wait() -> Result<()> {
8389
debug!("child pid = {pid}");
8490
let exitcode = wait_for_pid(pid)?;
8591
debug!("[pid {pid}] exitcode = {exitcode}");
92+
debug!("reaping children of supervisor!");
93+
reap_children()?;
8694
process::exit(exitcode);
8795
}
8896

@@ -423,6 +431,10 @@ impl Wrappable for CreateRequest {
423431

424432
let exitcode = wait_for_pid(pid)?;
425433
debug!("[pid {pid}] exitcode = {exitcode}");
434+
435+
debug!("reaping children of supervisor!");
436+
reap_children()?;
437+
426438
process::exit(exitcode);
427439
}
428440

0 commit comments

Comments
 (0)