summary refs log tree commit diff
path: root/devices/src/proxy.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2018-10-03 10:22:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-10-09 21:14:05 -0700
commit55a9e504beef368bd97e51ffd5a7fa6c034eb8ad (patch)
tree894d8685e2fdfa105ea35d1cb6cfceee06502c7a /devices/src/proxy.rs
parent046df60760f3b0691f23c27a7f24a96c9afe8c05 (diff)
downloadcrosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.gz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.bz2
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.lz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.xz
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.tar.zst
crosvm-55a9e504beef368bd97e51ffd5a7fa6c034eb8ad.zip
cargo fmt all source code
Now that cargo fmt has landed, run it over everything at once to bring
rust source to the standard formatting.

TEST=cargo test
BUG=None

Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b
Reviewed-on: https://chromium-review.googlesource.com/1259287
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'devices/src/proxy.rs')
-rw-r--r--devices/src/proxy.rs48
1 files changed, 28 insertions, 20 deletions
diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs
index 673a3c7..478625b 100644
--- a/devices/src/proxy.rs
+++ b/devices/src/proxy.rs
@@ -6,16 +6,16 @@
 
 use libc::pid_t;
 
-use std::{self, fmt, io};
 use std::os::unix::io::{AsRawFd, RawFd};
 use std::os::unix::net::UnixDatagram;
 use std::process;
 use std::time::Duration;
+use std::{self, fmt, io};
 
-use byteorder::{LittleEndian, NativeEndian, ByteOrder};
+use byteorder::{ByteOrder, LittleEndian, NativeEndian};
 
-use BusDevice;
 use io_jail::{self, Minijail};
+use BusDevice;
 
 /// Errors for proxy devices.
 #[derive(Debug)]
@@ -52,9 +52,11 @@ fn child_proc(sock: UnixDatagram, device: &mut BusDevice) {
         let mut buf = [0; MSG_SIZE];
         match handle_eintr!(sock.recv(&mut buf)) {
             Ok(c) if c != buf.len() => {
-                error!("child device process incorrect recv size: got {}, expected {}",
-                       c,
-                       buf.len());
+                error!(
+                    "child device process incorrect recv size: got {}, expected {}",
+                    c,
+                    buf.len()
+                );
                 break;
             }
             Err(e) => {
@@ -123,9 +125,11 @@ impl ProxyDevice {
     /// # Arguments
     /// * `device` - The device to isolate to another process.
     /// * `keep_fds` - File descriptors that will be kept open in the child
-    pub fn new<D: BusDevice>(mut device: D, jail: &Minijail, mut keep_fds: Vec<RawFd>)
-            -> Result<ProxyDevice>
-    {
+    pub fn new<D: BusDevice>(
+        mut device: D,
+        jail: &Minijail,
+        mut keep_fds: Vec<RawFd>,
+    ) -> Result<ProxyDevice> {
         let (child_sock, parent_sock) = UnixDatagram::pair().map_err(Error::Io)?;
 
         keep_fds.push(child_sock.as_raw_fd());
@@ -136,7 +140,7 @@ impl ProxyDevice {
                     child_proc(child_sock, &mut device);
                     // ! Never returns
                     process::exit(0);
-                },
+                }
                 p => p,
             }
         };
@@ -148,9 +152,9 @@ impl ProxyDevice {
             .set_read_timeout(Some(Duration::from_millis(SOCKET_TIMEOUT_MS)))
             .map_err(Error::Io)?;
         Ok(ProxyDevice {
-               sock: parent_sock,
-               pid: pid,
-           })
+            sock: parent_sock,
+            pid,
+        })
     }
 
     pub fn pid(&self) -> pid_t {
@@ -163,12 +167,12 @@ impl ProxyDevice {
         NativeEndian::write_u32(&mut buf[4..], len);
         NativeEndian::write_u64(&mut buf[8..], offset);
         buf[16..16 + data.len()].clone_from_slice(data);
-        handle_eintr!(self.sock.send(&buf)).map(|_| ()).map_err(Error::Io)
+        handle_eintr!(self.sock.send(&buf))
+            .map(|_| ())
+            .map_err(Error::Io)
     }
 
-    fn send_config_cmd(&self, cmd: Command, reg_idx: u32, offset: u64, data: &[u8])
-        -> Result<()>
-    {
+    fn send_config_cmd(&self, cmd: Command, reg_idx: u32, offset: u64, data: &[u8]) -> Result<()> {
         let mut buf = [0; MSG_SIZE];
         NativeEndian::write_u32(&mut buf[0..], cmd as u32);
         NativeEndian::write_u32(&mut buf[4..], reg_idx);
@@ -190,7 +194,9 @@ impl ProxyDevice {
 
     fn wait(&self) -> Result<()> {
         let mut buf = [0; MSG_SIZE];
-        handle_eintr!(self.sock.recv(&mut buf)).map(|_| ()).map_err(Error::Io)
+        handle_eintr!(self.sock.recv(&mut buf))
+            .map(|_| ())
+            .map_err(Error::Io)
     }
 
     pub fn config_register_write(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
@@ -216,7 +222,8 @@ impl ProxyDevice {
 
 impl BusDevice for ProxyDevice {
     fn read(&mut self, offset: u64, data: &mut [u8]) {
-        let res = self.send_cmd(Command::Read, offset, data.len() as u32, &[])
+        let res = self
+            .send_cmd(Command::Read, offset, data.len() as u32, &[])
             .and_then(|_| self.recv_resp(data));
         if let Err(e) = res {
             error!("failed read from child device process: {}", e);
@@ -224,7 +231,8 @@ impl BusDevice for ProxyDevice {
     }
 
     fn write(&mut self, offset: u64, data: &[u8]) {
-        let res = self.send_cmd(Command::Write, offset, data.len() as u32, data)
+        let res = self
+            .send_cmd(Command::Write, offset, data.len() as u32, data)
             .and_then(|_| self.wait());
         if let Err(e) = res {
             error!("failed write to child device process: {}", e);