From e6eeb715f359b6eaa7b5729a4e609765c3ccfb43 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 19 Jul 2022 16:03:09 -0700 Subject: [PATCH] main: clarify config parsing control flow It was a bit difficult to see that the config parsing errors would be printed out before init_log(); split it into a separate block to make it more understandable. BUG=b:239622092 TEST=tools/presubmit --all Change-Id: Id7fb76c706c2e9f5e0161dac28099bff95fd5f78 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3774317 Reviewed-by: Dennis Kempin Tested-by: Daniel Verkamp Commit-Queue: Dennis Kempin --- src/main.rs | 54 +++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 666cc3af83..db48362f79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,36 +79,38 @@ fn run_vm(cmd: RunCommand, log_config: LogConfig) -> Result) -> std::io::Result<()> + Sync + Send, { - match TryInto::::try_into(cmd) { - #[cfg(feature = "plugin")] - Ok(cfg) if executable_is_plugin(&cfg.executable_path) => { - match crosvm::plugin::run_config(cfg) { - Ok(_) => { - info!("crosvm and plugin have exited normally"); - Ok(CommandStatus::VmStop) - } - Err(e) => { - eprintln!("{:#}", e); - Err(e) - } - } - } - Ok(cfg) => { - #[cfg(feature = "crash-report")] - crosvm::sys::setup_emulator_crash_reporting(&cfg)?; - - #[cfg(windows)] - metrics::setup_metrics_reporting()?; - - init_log(log_config, &cfg)?; - let exit_state = crate::sys::run_config(cfg); - to_command_status(exit_state) - } + let cfg = match TryInto::::try_into(cmd) { + Ok(cfg) => cfg, Err(e) => { eprintln!("{}", e); - Err(anyhow!("{}", e)) + return Err(anyhow!("{}", e)); } + }; + + #[cfg(feature = "plugin")] + if executable_is_plugin(&cfg.executable_path) { + let res = match crosvm::plugin::run_config(cfg) { + Ok(_) => { + info!("crosvm and plugin have exited normally"); + Ok(CommandStatus::VmStop) + } + Err(e) => { + eprintln!("{:#}", e); + Err(e) + } + }; + return res; } + + #[cfg(feature = "crash-report")] + crosvm::sys::setup_emulator_crash_reporting(&cfg)?; + + #[cfg(windows)] + metrics::setup_metrics_reporting()?; + + init_log(log_config, &cfg)?; + let exit_state = crate::sys::run_config(cfg); + to_command_status(exit_state) } fn stop_vms(cmd: cmdline::StopCommand) -> std::result::Result<(), ()> {