From d011b39e9670792c502515439ae06571d6c9b561 Mon Sep 17 00:00:00 2001 From: lifupan Date: Tue, 12 Nov 2019 23:26:55 +0800 Subject: [PATCH] agent: init agent as init before parsing cmd line When kata-agent run as init process in initrd, do the init in which will do some base mount such as mount /proc; thus the following config.parse_cmdline can access /proc/cmdline to parse the parameters such as agent.log etc. Fixes: #85 Signed-off-by: lifupan --- src/agent/src/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 6850f357c9..77c2087aab 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -96,10 +96,20 @@ 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 + // since before do the base mount, it wouldn't access "/proc/cmdline" + // to get the customzied debug level. + let writer = io::stdout(); + let logger = logging::create_logger(NAME, "agent", slog::Level::Debug, writer); + init_agent_as_init(&logger)?; + } + config.parse_cmdline(KERNEL_CMDLINE_FILE)?; 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); announce(&logger); @@ -126,10 +136,6 @@ fn main() -> Result<()> { unsafe { MaybeUninit::zeroed().assume_init() } }; - if unistd::getpid() == Pid::from_raw(1) { - init_agent_as_init(&logger)?; - } - // Initialize unique sandbox structure. let s = Sandbox::new(&logger).map_err(|e| { error!(logger, "Failed to create sandbox with error: {:?}", e);