From 6b611030db8054951bdb637f737e207b130c4c1e Mon Sep 17 00:00:00 2001 From: lifupan Date: Tue, 19 Nov 2019 18:00:37 +0800 Subject: [PATCH] agent: fix the issue dead lock on AGENT_CONFIG Once parsed cmdline and set the config on AGENT_CONFIG, release the write lock as soon as possible. In case other thread would get read lock on it. Fixes:#87 Signed-off-by: lifupan --- src/agent/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 2c69f2f4c..a96491178 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -104,7 +104,6 @@ fn main() -> Result<()> { lazy_static::initialize(&AGENT_CONFIG); let agentConfig = AGENT_CONFIG.clone(); - let mut config = agentConfig.write().unwrap(); if unistd::getpid() == Pid::from_raw(1) { // Init a temporary logger used by init agent as init process @@ -115,8 +114,15 @@ fn main() -> Result<()> { init_agent_as_init(&logger)?; } - config.parse_cmdline(KERNEL_CMDLINE_FILE)?; + // once parsed cmdline and set the config, release the write lock + // as soon as possible in case other thread would get read lock on + // it. + { + let mut config = agentConfig.write().unwrap(); + config.parse_cmdline(KERNEL_CMDLINE_FILE)?; + } + let config = agentConfig.read().unwrap(); let writer = io::stdout(); // Recreate a logger with the log level get from "/proc/cmdline". let logger = logging::create_logger(NAME, "agent", config.log_level, writer);