Support sending VM log output to a file.
Bug: 191613547
Test: Ran VM manually with log to file and without
Change-Id: I2bc0c3e76c537e5e5ce762d902806482d4820af5
diff --git a/vm/src/run.rs b/vm/src/run.rs
index ab4222f..ec95646 100644
--- a/vm/src/run.rs
+++ b/vm/src/run.rs
@@ -36,12 +36,21 @@
service: Strong<dyn IVirtualizationService>,
config_path: &Path,
daemonize: bool,
+ log_path: Option<&Path>,
) -> Result<(), Error> {
let config_file = File::open(config_path).context("Failed to open config file")?;
let config =
VmConfig::load(&config_file).context("Failed to parse config file")?.to_parcelable()?;
- let stdout =
- if daemonize { None } else { Some(ParcelFileDescriptor::new(duplicate_stdout()?)) };
+ let stdout = if let Some(log_path) = log_path {
+ Some(ParcelFileDescriptor::new(
+ File::create(log_path)
+ .with_context(|| format!("Failed to open log file {:?}", log_path))?,
+ ))
+ } else if daemonize {
+ None
+ } else {
+ Some(ParcelFileDescriptor::new(duplicate_stdout()?))
+ };
let vm = service.startVm(&config, stdout.as_ref()).context("Failed to start VM")?;
let cid = vm.getCid().context("Failed to get CID")?;