Merge pull request #86 from lifupan/fix_initrd_panic

agent: init agent as init before parsing cmd line
This commit is contained in:
Xu Wang
2019-11-13 01:03:48 +08:00
committed by GitHub

View File

@@ -98,10 +98,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);
@@ -128,10 +138,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);