]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/unix/process/process_fuchsia.rs
Format libstd/sys with rustfmt
[rust.git] / src / libstd / sys / unix / process / process_fuchsia.rs
index 2b1a3ecfd70f590fd57977841ce18bb1610e02e5..f0bd1cdfed52f0a2c250aeffb44284d31dda32cc 100644 (file)
@@ -1,11 +1,11 @@
 use crate::convert::TryInto;
-use crate::io;
 use crate::fmt;
+use crate::io;
 use crate::mem;
 use crate::ptr;
 
-use crate::sys::process::zircon::{Handle, zx_handle_t};
 use crate::sys::process::process_common::*;
+use crate::sys::process::zircon::{zx_handle_t, Handle};
 
 use libc::{c_int, size_t};
 
 ////////////////////////////////////////////////////////////////////////////////
 
 impl Command {
-    pub fn spawn(&mut self, default: Stdio, needs_stdin: bool)
-                 -> io::Result<(Process, StdioPipes)> {
+    pub fn spawn(
+        &mut self,
+        default: Stdio,
+        needs_stdin: bool,
+    ) -> io::Result<(Process, StdioPipes)> {
         let envp = self.capture_env();
 
         if self.saw_nul() {
-            return Err(io::Error::new(io::ErrorKind::InvalidInput,
-                                      "nul byte found in provided data"));
+            return Err(io::Error::new(
+                io::ErrorKind::InvalidInput,
+                "nul byte found in provided data",
+            ));
         }
 
         let (ours, theirs) = self.setup_io(default, needs_stdin)?;
@@ -32,21 +37,23 @@ pub fn spawn(&mut self, default: Stdio, needs_stdin: bool)
 
     pub fn exec(&mut self, default: Stdio) -> io::Error {
         if self.saw_nul() {
-            return io::Error::new(io::ErrorKind::InvalidInput,
-                                  "nul byte found in provided data")
+            return io::Error::new(io::ErrorKind::InvalidInput, "nul byte found in provided data");
         }
 
         match self.setup_io(default, true) {
             Ok((_, _)) => {
                 // FIXME: This is tough because we don't support the exec syscalls
                 unimplemented!();
-            },
+            }
             Err(e) => e,
         }
     }
 
-    unsafe fn do_exec(&mut self, stdio: ChildPipes, maybe_envp: Option<&CStringArray>)
-                      -> io::Result<zx_handle_t> {
+    unsafe fn do_exec(
+        &mut self,
+        stdio: ChildPipes,
+        maybe_envp: Option<&CStringArray>,
+    ) -> io::Result<zx_handle_t> {
         use crate::sys::process::zircon::*;
 
         let envp = match maybe_envp {
@@ -108,10 +115,15 @@ unsafe fn do_exec(&mut self, stdio: ChildPipes, maybe_envp: Option<&CStringArray
         let mut process_handle: zx_handle_t = 0;
         zx_cvt(fdio_spawn_etc(
             ZX_HANDLE_INVALID,
-            FDIO_SPAWN_CLONE_JOB | FDIO_SPAWN_CLONE_LDSVC | FDIO_SPAWN_CLONE_NAMESPACE
-            | FDIO_SPAWN_CLONE_ENVIRON,  // this is ignored when envp is non-null
-            self.get_argv()[0], self.get_argv().as_ptr(), envp,
-            actions.len() as size_t, actions.as_ptr(),
+            FDIO_SPAWN_CLONE_JOB
+                | FDIO_SPAWN_CLONE_LDSVC
+                | FDIO_SPAWN_CLONE_NAMESPACE
+                | FDIO_SPAWN_CLONE_ENVIRON, // this is ignored when envp is non-null
+            self.get_program().as_ptr(),
+            self.get_argv().as_ptr(),
+            envp,
+            actions.len() as size_t,
+            actions.as_ptr(),
             &mut process_handle,
             ptr::null_mut(),
         ))?;
@@ -137,7 +149,9 @@ pub fn id(&self) -> u32 {
     pub fn kill(&mut self) -> io::Result<()> {
         use crate::sys::process::zircon::*;
 
-        unsafe { zx_cvt(zx_task_kill(self.handle.raw()))?; }
+        unsafe {
+            zx_cvt(zx_task_kill(self.handle.raw()))?;
+        }
 
         Ok(())
     }
@@ -151,16 +165,26 @@ pub fn wait(&mut self) -> io::Result<ExitStatus> {
         let mut avail: size_t = 0;
 
         unsafe {
-            zx_cvt(zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED,
-                                      ZX_TIME_INFINITE, ptr::null_mut()))?;
-            zx_cvt(zx_object_get_info(self.handle.raw(), ZX_INFO_PROCESS,
-                                      &mut proc_info as *mut _ as *mut libc::c_void,
-                                      mem::size_of::<zx_info_process_t>(), &mut actual,
-                                      &mut avail))?;
+            zx_cvt(zx_object_wait_one(
+                self.handle.raw(),
+                ZX_TASK_TERMINATED,
+                ZX_TIME_INFINITE,
+                ptr::null_mut(),
+            ))?;
+            zx_cvt(zx_object_get_info(
+                self.handle.raw(),
+                ZX_INFO_PROCESS,
+                &mut proc_info as *mut _ as *mut libc::c_void,
+                mem::size_of::<zx_info_process_t>(),
+                &mut actual,
+                &mut avail,
+            ))?;
         }
         if actual != 1 {
-            return Err(io::Error::new(io::ErrorKind::InvalidData,
-                                      "Failed to get exit status of process"));
+            return Err(io::Error::new(
+                io::ErrorKind::InvalidData,
+                "Failed to get exit status of process",
+            ));
         }
         Ok(ExitStatus(proc_info.return_code))
     }
@@ -174,23 +198,31 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
         let mut avail: size_t = 0;
 
         unsafe {
-            let status = zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED,
-                                            0, ptr::null_mut());
+            let status =
+                zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED, 0, ptr::null_mut());
             match status {
-                0 => { }, // Success
+                0 => {} // Success
                 x if x == ERR_TIMED_OUT => {
                     return Ok(None);
-                },
-                _ => { panic!("Failed to wait on process handle: {}", status); },
+                }
+                _ => {
+                    panic!("Failed to wait on process handle: {}", status);
+                }
             }
-            zx_cvt(zx_object_get_info(self.handle.raw(), ZX_INFO_PROCESS,
-                                      &mut proc_info as *mut _ as *mut libc::c_void,
-                                      mem::size_of::<zx_info_process_t>(), &mut actual,
-                                      &mut avail))?;
+            zx_cvt(zx_object_get_info(
+                self.handle.raw(),
+                ZX_INFO_PROCESS,
+                &mut proc_info as *mut _ as *mut libc::c_void,
+                mem::size_of::<zx_info_process_t>(),
+                &mut actual,
+                &mut avail,
+            ))?;
         }
         if actual != 1 {
-            return Err(io::Error::new(io::ErrorKind::InvalidData,
-                                      "Failed to get exit status of process"));
+            return Err(io::Error::new(
+                io::ErrorKind::InvalidData,
+                "Failed to get exit status of process",
+            ));
         }
         Ok(Some(ExitStatus(proc_info.return_code)))
     }