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 <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Daniel Verkamp 2022-07-19 16:03:09 -07:00 committed by crosvm LUCI
parent f0d2ddddf5
commit e6eeb715f3

View file

@ -79,36 +79,38 @@ fn run_vm<F: 'static>(cmd: RunCommand, log_config: LogConfig<F>) -> Result<Comma
where
F: Fn(&mut syslog::fmt::Formatter, &log::Record<'_>) -> std::io::Result<()> + Sync + Send,
{
match TryInto::<Config>::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::<Config>::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<(), ()> {