Fix daemonization

This commit is contained in:
elkowar 2021-08-14 14:03:16 +02:00
parent 096aedc0d4
commit e72a16a5bd
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F

View file

@ -181,7 +181,13 @@ pub enum ForkResult {
fn do_detach(log_file_path: impl AsRef<Path>) -> Result<ForkResult> {
// detach from terminal
match unsafe { nix::unistd::fork()? } {
nix::unistd::ForkResult::Child => {}
nix::unistd::ForkResult::Child => {
nix::unistd::setsid()?;
match unsafe {nix::unistd::fork()?
}{
nix::unistd::ForkResult::Parent { .. } => std::process::exit(0),
nix::unistd::ForkResult::Child => {}
}}
nix::unistd::ForkResult::Parent { .. } => {
return Ok(ForkResult::Parent);
}