diff --git a/Cargo.lock b/Cargo.lock index 0bb2cfb..a8677da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,6 +982,7 @@ version = "0.1.0" dependencies = [ "cosmic-text 0.10.0", "env_logger", + "fork", "i18n-embed", "i18n-embed-fl", "lazy_static", @@ -1837,6 +1838,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "fork" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2ca97a59201425e7ee4d197c9c4fea282fe87a97d666a580bda889b95b8e88" +dependencies = [ + "libc", +] + [[package]] name = "form_urlencoded" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 3540b10..c2865b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ license = "GPL-3.0-only" [dependencies] env_logger = "0.10.0" +fork = "0.1" lazy_static = "1.4.0" log = "0.4.20" notify = "6.1.1" diff --git a/src/main.rs b/src/main.rs index 628bf35..27d49bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,6 +60,15 @@ lazy_static::lazy_static! { } fn main() -> Result<(), Box> { + match fork::daemon(false, false) { + Ok(fork::Fork::Child) => (), + Ok(fork::Fork::Parent(_child_pid)) => process::exit(0), + Err(err) => { + eprintln!("failed to daemonize: {:?}", err); + process::exit(1); + } + } + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); localize::localize();