From 05ec00698f8e0f8c957197d129a5ab87977595f8 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sun, 15 Sep 2019 16:04:27 +0200 Subject: [PATCH] Fix #32 --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 09f62e3..7a3e4e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -290,6 +290,15 @@ fn start_main(config_set: ConfigSet) { if sid < 0 { exit(5); } + + // Detach stdout and stderr + let null_path = std::ffi::CString::new("/dev/null").expect("CString unwrap failed"); + let fd = libc::open(null_path.as_ptr(), libc::O_RDWR, 0); + if fd != -1 { + libc::dup2(fd, libc::STDIN_FILENO); + libc::dup2(fd, libc::STDOUT_FILENO); + libc::dup2(fd, libc::STDERR_FILENO); + } } daemon_main(config_set);