Send logd logs from VM to host
When the debug level of a VM is not "none", logd logs from the VM is
sent to the host. This is done by running the VM with another virtual
console and running logcat as a daemon process whose output is set to
the new virtual console device. The launch of the daemon process is
controlled by microdroid. It starts the process only when the debug
level is set to above "none".
For now, the virtual console device is backed by the same file
descriptor as the kernel console logs. A follow-up change will introduce
a new dedicated file descriptor.
Bug: 200914564
Test: start microdroid using the `vm` tool. logcat logs are shown in
stdout.
Change-Id: I1748d30c5c997cda73f7b9f082ca84b0b3d25f1e
diff --git a/microdroid_manager/src/main.rs b/microdroid_manager/src/main.rs
index ac62e58..a2fab07 100644
--- a/microdroid_manager/src/main.rs
+++ b/microdroid_manager/src/main.rs
@@ -49,6 +49,7 @@
const VMADDR_CID_HOST: u32 = 2;
const APEX_CONFIG_DONE_PROP: &str = "apex_config.done";
+const LOGD_ENABLED_PROP: &str = "ro.boot.logd.enabled";
fn get_vms_rpc_binder() -> Result<Strong<dyn IVirtualMachineService>> {
// SAFETY: AIBinder returned by RpcClient has correct reference count, and the ownership can be
@@ -223,6 +224,12 @@
info!("notifying payload started");
service.notifyPayloadStarted()?;
+ // Start logging if enabled
+ // TODO(b/200914564) set filterspec if debug_level is app_only
+ if system_properties::read(LOGD_ENABLED_PROP)? == "1" {
+ system_properties::write("ctl.start", "seriallogging")?;
+ }
+
let exit_status = command.spawn()?.wait()?;
if let Some(code) = exit_status.code() {
info!("notifying payload finished");