From 3e00bdffafb1b7fcfccce6b4a2332aa2e5eaea49 Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Tue, 16 Jun 2020 15:40:45 +0800 Subject: [PATCH] agent: fix the issue of broken logger for agent as init process Dup a new file descriptor for temporary logger writer, since this logger would be dropped and it's writer would be closed out of if definition scope, which would cause the logger process thread terminated if it used the original pipe write fd. Fixes: #318 Signed-off-by: fupan.lfp --- src/agent/src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index a2f6370647..e925e6a1b7 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -31,6 +31,7 @@ use nix::fcntl::{self, OFlag}; use nix::sys::socket::{self, AddressFamily, SockAddr, SockFlag, SockType}; use nix::sys::wait::{self, WaitStatus}; use nix::unistd; +use nix::unistd::dup; use prctl::set_child_subreaper; use rustjail::errors::*; use signal_hook::{iterator::Signals, SIGCHLD}; @@ -117,6 +118,12 @@ fn main() -> Result<()> { let agentConfig = AGENT_CONFIG.clone(); if unistd::getpid() == Pid::from_raw(1) { + // dup a new file descriptor for this temporary logger writer, + // since this logger would be dropped and it's writer would + // be closed out of this code block. + let newwfd = dup(wfd)?; + let writer = unsafe { File::from_raw_fd(newwfd) }; + // Init a temporary logger used by init agent as init process // since before do the base mount, it wouldn't access "/proc/cmdline" // to get the customzied debug level.