Add daemon mode support

This commit is contained in:
Hugo 2025-03-22 12:50:18 -04:00 committed by Jeremy Soller
parent b59418e60b
commit 07ed2615d0
3 changed files with 24 additions and 1 deletions

View file

@ -68,7 +68,17 @@ fn language_name(code: &str) -> Option<String> {
/// Runs application with these settings
#[rustfmt::skip]
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(all(unix, not(target_os = "redox")))]
match fork::daemon(true, true) {
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();