From 6fa8da3c434ef25f14f1eb801d32ac613e758c10 Mon Sep 17 00:00:00 2001 From: Alexey <247128645+axkurcom@users.noreply.github.com> Date: Wed, 30 Sep 2026 07:40:01 +0300 Subject: [PATCH] Daemon stdio ownership and cover runtime path policies fixed Co-Authored-By: brekotis <93345790+brekotis@users.noreply.github.com> --- src/daemon/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/daemon/mod.rs b/src/daemon/mod.rs index a3a8b80..3a0da2a 100644 --- a/src/daemon/mod.rs +++ b/src/daemon/mod.rs @@ -9,7 +9,7 @@ use std::os::unix::fs::OpenOptionsExt; use std::path::{Path, PathBuf}; use nix::errno::Errno; -use nix::unistd::{self, ForkResult, Gid, Uid, chdir, close, fork, getpid, setsid}; +use nix::unistd::{self, ForkResult, Gid, Uid, chdir, fork, getpid, setsid}; use tracing::info; // PID file ownership and process-control helpers. @@ -176,8 +176,10 @@ fn redirect_stdio_to_devnull() -> Result<(), DaemonError> { } } - if devnull_fd > 2 { - let _ = close(devnull_fd); + // Keep stdio descriptors open; other source descriptors are closed once by File's Drop. + // Transfer ownership only after all dup2 calls succeed so errors retain RAII cleanup. + if devnull_fd <= 2 { + let _ = std::os::unix::io::IntoRawFd::into_raw_fd(devnull); } Ok(())