Merge pull request #445 from mahkoh/jorth/reexec-double-fork
reexec: double-fork to prevent the creation of zombies
This commit is contained in:
commit
7eb47a42c2
1 changed files with 30 additions and 21 deletions
|
|
@ -12,7 +12,7 @@ use {
|
|||
},
|
||||
std::{array::from_mut, cell::RefCell, rc::Rc},
|
||||
thiserror::Error,
|
||||
uapi::{OwnedFd, UstrPtr, c, close_range, dup2, pipe2},
|
||||
uapi::{OwnedFd, UstrPtr, c, close_range, dup2, pipe2, waitpid},
|
||||
};
|
||||
|
||||
pub struct JayReexec {
|
||||
|
|
@ -50,6 +50,12 @@ impl JayReexec {
|
|||
}
|
||||
let (p1, c1) = pipe!();
|
||||
let (c2, p2) = pipe!();
|
||||
if let Ok(f) = fork_with_pidfd(false) {
|
||||
match f {
|
||||
Forked::Parent { pid, .. } => {
|
||||
let _ = waitpid(pid, 0);
|
||||
}
|
||||
Forked::Child { .. } => {
|
||||
if let Ok(f) = fork_with_pidfd(false) {
|
||||
if let Forked::Child { .. } = f {
|
||||
drop(p2);
|
||||
|
|
@ -70,11 +76,14 @@ impl JayReexec {
|
|||
revents: 0,
|
||||
};
|
||||
let _ = uapi::poll(from_mut(&mut pollfd), -1);
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
c::_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(c1);
|
||||
let mut pollfd = c::pollfd {
|
||||
fd: p1.raw(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue