From 9ac7ca65fd9044a8212b8441fa5697f581ee74b6 Mon Sep 17 00:00:00 2001 From: Junichi Uekawa Date: Tue, 23 Aug 2022 19:17:35 +0900 Subject: [PATCH] crosvm: unix: Do not keep around a reference to minijail. minijail object destructor only frees memory regions, we don't need to keep it around. BUG=b:238646369 TEST=build. Change-Id: Ia736d4b6e1ccc4bb476e8fda18981259d271a36f Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3850109 Reviewed-by: Alexandre Courbot Commit-Queue: Junichi Uekawa Tested-by: Junichi Uekawa --- src/crosvm/sys/unix.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/crosvm/sys/unix.rs b/src/crosvm/sys/unix.rs index 62b17c33a9..4ba154c7fc 100644 --- a/src/crosvm/sys/unix.rs +++ b/src/crosvm/sys/unix.rs @@ -2784,13 +2784,13 @@ fn run_control( /// The jailing business is nasty and potentially unsafe if done from the wrong context - do not /// call outside of `start_devices`! /// -/// Returns the jail the device process is running in, as well as its pid. +/// Returns the pid of the jailed device process. fn jail_and_start_vu_device( jail_config: &Option, params: &T, vhost: &str, name: &str, -) -> anyhow::Result<(Minijail, libc::pid_t, Option>)> { +) -> anyhow::Result<(libc::pid_t, Option>)> { let mut keep_rds = Vec::new(); base::syslog::push_descriptors(&mut keep_rds); @@ -2857,7 +2857,7 @@ fn jail_and_start_vu_device( // to clean up ourselves. info!("process for device {} (PID {}) started", &name, pid); - Ok((jail, pid, parent_resources)) + Ok((pid, parent_resources)) } } } @@ -2866,12 +2866,7 @@ pub fn start_devices(opts: DevicesCommand) -> anyhow::Result<()> { struct DeviceJailInfo { // Unique name for the device, in the form `foomatic-0`. name: String, - // Jail the device process is running in. - // We are just keeping it alive for as long as the device process needs to run. - #[allow(dead_code)] - jail: Minijail, - #[allow(dead_code)] - drop_resources: Option>, + _drop_resources: Option>, } fn add_device( @@ -2883,15 +2878,14 @@ pub fn start_devices(opts: DevicesCommand) -> anyhow::Result<()> { ) -> anyhow::Result<()> { let name = format!("{}-{}", T::NAME, i); - let (jail, pid, drop_resources) = + let (pid, _drop_resources) = jail_and_start_vu_device::(jail_config, device_params, vhost, &name)?; devices_jails.insert( pid, DeviceJailInfo { name, - jail, - drop_resources, + _drop_resources, }, );