From fa4b2990b228431f6471fb147b4d1efa5a1b5373 Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Mon, 2 Oct 2023 12:43:33 +0100 Subject: [PATCH] fix: Move argument passing up Moves argument passing before logging `Running Firecracker` and other code that may not be required if certain arguments are passed causing the process to exit early. Signed-off-by: Jonathan Woollett-Light --- src/firecracker/src/main.rs | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/firecracker/src/main.rs b/src/firecracker/src/main.rs index b39ef1cbf67..5b237b02bae 100644 --- a/src/firecracker/src/main.rs +++ b/src/firecracker/src/main.rs @@ -104,25 +104,6 @@ fn main() -> ExitCode { fn main_exec() -> Result<(), MainError> { // Initialize the logger. LOGGER.init().map_err(MainError::SetLogger)?; - info!("Running Firecracker v{FIRECRACKER_VERSION}"); - - register_signal_handlers().map_err(MainError::RegisterSignalHandlers)?; - - #[cfg(target_arch = "aarch64")] - enable_ssbd_mitigation(); - - if let Err(err) = resize_fdtable() { - match err { - // These errors are non-critical: In the worst case we have worse snapshot restore - // performance. - ResizeFdTableError::GetRlimit | ResizeFdTableError::Dup2(_) => { - debug!("Failed to resize fdtable: {err}") - } - // This error means that we now have a random file descriptor lying around, abort to be - // cautious. - ResizeFdTableError::Close(_) => return Err(MainError::ResizeFdtable(err)), - } - } // We need this so that we can reset terminal to canonical mode if panic occurs. let stdin = io::stdin(); @@ -281,6 +262,26 @@ fn main_exec() -> Result<(), MainError> { return Ok(()); } + info!("Running Firecracker v{FIRECRACKER_VERSION}"); + + register_signal_handlers().map_err(MainError::RegisterSignalHandlers)?; + + #[cfg(target_arch = "aarch64")] + enable_ssbd_mitigation(); + + if let Err(err) = resize_fdtable() { + match err { + // These errors are non-critical: In the worst case we have worse snapshot restore + // performance. + ResizeFdTableError::GetRlimit | ResizeFdTableError::Dup2(_) => { + debug!("Failed to resize fdtable: {err}") + } + // This error means that we now have a random file descriptor lying around, abort to be + // cautious. + ResizeFdTableError::Close(_) => return Err(MainError::ResizeFdtable(err)), + } + } + // Display warnings for any used deprecated parameters. // Currently unused since there are no deprecated parameters. Uncomment the line when // deprecating one.