diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 665d3a0261..25b6218b51 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -126,15 +126,6 @@ fn main() -> Result<()> { let writer = unsafe { File::from_raw_fd(wfd) }; let agentConfig = AGENT_CONFIG.clone(); - // 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 init_mode = unistd::getpid() == Pid::from_raw(1); if init_mode { @@ -148,8 +139,25 @@ fn main() -> Result<()> { // since before do the base mount, it wouldn't access "/proc/cmdline" // to get the customzied debug level. let logger = logging::create_logger(NAME, "agent", slog::Level::Debug, writer); + + // Must mount proc fs before parsing kernel command line + general_mount(&logger).map_err(|e| { + error!(logger, "fail general mount: {}", e); + e + })?; + + let mut config = agentConfig.write().unwrap(); + config.parse_cmdline(KERNEL_CMDLINE_FILE)?; + init_agent_as_init(&logger, config.unified_cgroup_hierarchy)?; + } else { + // 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 log_vport = config.log_vport as u32; let log_handle = thread::spawn(move || -> Result<()> { @@ -335,8 +343,13 @@ fn setup_signal_handler(logger: &Logger, sandbox: Arc>) -> Result // init_agent_as_init will do the initializations such as setting up the rootfs // when this agent has been run as the init process. fn init_agent_as_init(logger: &Logger, unified_cgroup_hierarchy: bool) -> Result<()> { - general_mount(logger)?; - cgroups_mount(logger, unified_cgroup_hierarchy)?; + cgroups_mount(logger, unified_cgroup_hierarchy).map_err(|e| { + error!( + logger, + "fail cgroups mount, unified_cgroup_hierarchy {}: {}", unified_cgroup_hierarchy, e + ); + e + })?; fs::remove_file(Path::new("/dev/ptmx"))?; unixfs::symlink(Path::new("/dev/pts/ptmx"), Path::new("/dev/ptmx"))?;