diff options
author | Zach Reizner <zachr@google.com> | 2019-12-12 18:58:50 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-09 07:53:57 +0000 |
commit | 19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85 (patch) | |
tree | 5465440731391ebbb4d69776b2a29489a4eeadfa /devices/src/proxy.rs | |
parent | 58df38b61519222911baa761ffd26da93613dbf6 (diff) | |
download | crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar.gz crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar.bz2 crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar.lz crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar.xz crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.tar.zst crosvm-19ad1f3d3a24b25878f03c6f3bb917c4ae28ce85.zip |
devices: remove user_command from proxy device
The only device that used user_command was Serial. This change makes Serial device use a thread to read from its input instead of using user_command. BUG=chromium:1033787 TEST=./build_test run crosvm with stdio serial with and without sandbox Change-Id: Ia0f2ee83d94ad2fee3f1f4f89aa734b976e33507 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1966435 Tested-by: Zach Reizner <zachr@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Zach Reizner <zachr@chromium.org> Auto-Submit: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'devices/src/proxy.rs')
-rw-r--r-- | devices/src/proxy.rs | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs index 927ea7a..cb7ebd6 100644 --- a/devices/src/proxy.rs +++ b/devices/src/proxy.rs @@ -56,7 +56,6 @@ enum Command { data: [u8; 4], }, Shutdown, - RunUserCommand, } #[derive(MsgOnSocket)] @@ -66,11 +65,7 @@ enum CommandResult { ReadConfigResult(u32), } -fn child_proc<D: BusDevice, F: FnMut(&mut D)>( - sock: UnixSeqpacket, - device: &mut D, - mut user_command: F, -) { +fn child_proc<D: BusDevice>(sock: UnixSeqpacket, device: &mut D) { let mut running = true; let sock = MsgSocket::<CommandResult, Command>::new(sock); @@ -114,10 +109,6 @@ fn child_proc<D: BusDevice, F: FnMut(&mut D)>( running = false; sock.send(&CommandResult::Ok) } - Command::RunUserCommand => { - user_command(device); - sock.send(&CommandResult::Ok) - } }; if let Err(e) = res { error!("child device process failed send: {}", e); @@ -146,31 +137,9 @@ impl ProxyDevice { /// * `jail` - The jail to use for isolating the given device. /// * `keep_fds` - File descriptors that will be kept open in the child. pub fn new<D: BusDevice>( - device: D, - jail: &Minijail, - keep_fds: Vec<RawFd>, - ) -> Result<ProxyDevice> { - Self::new_with_user_command(device, jail, keep_fds, |_| {}) - } - - /// Similar to `ProxyDevice::new`, but adds an additional custom command to be run in the forked - /// process when `run_user_command` is called. - /// - /// Note that the custom command closure is run in the main thread of the child process, which - /// also services `BusDevice` requests. Therefore, do not run blocking calls in the closure - /// without a timeout, or you will block any VCPU which touches this device, and every other - /// thread which needs to lock this device's mutex. - /// - /// # Arguments - /// * `device` - The device to isolate to another process. - /// * `jail` - The jail to use for isolating the given device. - /// * `keep_fds` - File descriptors that will be kept open in the child. - /// * `user_command` - Closure to be run in the forked process. - pub fn new_with_user_command<D: BusDevice, F: FnMut(&mut D)>( mut device: D, jail: &Minijail, mut keep_fds: Vec<RawFd>, - user_command: F, ) -> Result<ProxyDevice> { let debug_label = device.debug_label(); let (child_sock, parent_sock) = UnixSeqpacket::pair().map_err(Error::Io)?; @@ -181,7 +150,7 @@ impl ProxyDevice { match jail.fork(Some(&keep_fds)).map_err(Error::ForkingJail)? { 0 => { device.on_sandboxed(); - child_proc(child_sock, &mut device, user_command); + child_proc(child_sock, &mut device); // We're explicitly not using std::process::exit here to avoid the cleanup of // stdout/stderr globals. This can cause cascading panics and SIGILL if a worker @@ -214,11 +183,6 @@ impl ProxyDevice { self.pid } - /// Runs the callback given in `new_with_custom_command` in the child device process. - pub fn run_user_command(&self) { - self.sync_send(&Command::RunUserCommand); - } - /// Send a command that does not expect a response from the child device process. fn send_no_result(&self, cmd: &Command) { let res = self.sock.send(cmd); |