about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheodore DeRego <tedsta@google.com>2016-11-22 16:08:48 -0800
committerTheodore DeRego <tedsta@google.com>2016-11-22 16:08:48 -0800
commitfae86b92dec2a7439a071270193c3c72b65b7ccd (patch)
treef36f240a6c33089ff39edadd28330838fd4640d4
parent5c23f2e3c88275cee37acbd36c12baba57c4de2b (diff)
downloadrust-fae86b92dec2a7439a071270193c3c72b65b7ccd.tar.gz
rust-fae86b92dec2a7439a071270193c3c72b65b7ccd.zip
Cleaned up and appeased the linter
-rw-r--r--src/libstd/process.rs13
-rw-r--r--src/libstd/sys/unix/magenta.rs2
-rw-r--r--src/libstd/sys/unix/process.rs92
3 files changed, 30 insertions, 77 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index a9c68e82175..0b59de55cc6 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -780,8 +780,6 @@ impl Child {
     ///
     #[stable(feature = "process", since = "1.0.0")]
     pub fn wait_with_output(mut self) -> io::Result<Output> {
-        //use io::ErrorKind;
-
         drop(self.stdin.take());
 
         let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
@@ -796,15 +794,8 @@ impl Child {
                 res.unwrap();
             }
             (Some(out), Some(err)) => {
-                match read2(out.inner, &mut stdout, err.inner, &mut stderr) {
-                    Ok(()) => { },
-                    #[cfg(not(target_os = "fuchsia"))]
-                    Err(ref e) => { panic!("Failed to read child's stdout and stderr: {:?}", e); },
-                    #[cfg(target_os = "fuchsia")]
-                    Err(_) => {
-                        // FIXME: Right now there's a bug in magenta's pipes implementation
-                    },
-                }
+                let res = read2(out.inner, &mut stdout, err.inner, &mut stderr);
+                res.update();
             }
         }
 
diff --git a/src/libstd/sys/unix/magenta.rs b/src/libstd/sys/unix/magenta.rs
index ae3b7789b10..9da827c7d31 100644
--- a/src/libstd/sys/unix/magenta.rs
+++ b/src/libstd/sys/unix/magenta.rs
@@ -28,8 +28,6 @@ pub const MX_HANDLE_INVALID: mx_handle_t = 0;
 pub type mx_time_t = u64;
 pub const MX_TIME_INFINITE : mx_time_t = u64::MAX;
 
-pub const NO_ERROR              : mx_status_t = 0;
-
 pub type mx_signals_t = u32;
 
 pub const MX_OBJECT_SIGNAL_3         : mx_signals_t = 1 << 3;
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index aa203dc6215..d660514a983 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -309,18 +309,9 @@ impl Command {
 
         let (ours, theirs) = self.setup_io(default, needs_stdin)?;
 
-        let (maybe_process, err) = unsafe { self.do_exec(&theirs) };
-        // We don't want FileDesc::drop to be called on any stdio. It would close their handles.
-        let ChildPipes { stdin: their_stdin, stdout: their_stdout, stderr: their_stderr } = theirs;
-        their_stdin.fd();
-        their_stdout.fd();
-        their_stderr.fd();
-
-        if let Some((launchpad, process_handle)) = maybe_process {
-            Ok((Process { launchpad: launchpad, handle: process_handle, status: None }, ours))
-        } else {
-            Err(err)
-        }
+        let (launchpad, process_handle) = unsafe { self.do_exec(theirs)? };
+
+        Ok((Process { launchpad: launchpad, handle: process_handle, status: None }, ours))
     }
 
     #[cfg(not(target_os = "fuchsia"))]
@@ -453,23 +444,16 @@ impl Command {
     }
 
     #[cfg(target_os = "fuchsia")]
-    unsafe fn do_exec(&mut self, stdio: &ChildPipes)
-                      -> (Option<(*mut launchpad_t, mx_handle_t)>, io::Error) {
+    unsafe fn do_exec(&mut self, stdio: ChildPipes)
+                      -> io::Result<(*mut launchpad_t, mx_handle_t)> {
         use sys::magenta::*;
 
-        macro_rules! t {
-            ($e:expr) => (match $e {
-                Ok(e) => e,
-                Err(e) => return (None, e),
-            })
-        }
-
         macro_rules! tlp {
             ($lp:expr, $e:expr) => (match $e {
                 Ok(e) => e,
                 Err(e) => {
                     launchpad_destroy($lp);
-                    return (None, e);
+                    return Err(e);
                 },
             })
         }
@@ -484,46 +468,23 @@ impl Command {
         let mut job_copy: mx_handle_t = MX_HANDLE_INVALID;
 
         // Duplicate the job handle
-        t!(mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS,
-                                   &mut job_copy as *mut mx_handle_t)));
+        mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS,
+                                   &mut job_copy as *mut mx_handle_t))?;
         // Create a launchpad
-        t!(mx_cvt(launchpad_create(job_copy, self.argv[0],
-                                &mut launchpad as *mut *mut launchpad_t)));
+        mx_cvt(launchpad_create(job_copy, self.argv[0],
+                                &mut launchpad as *mut *mut launchpad_t))?;
         // Set the process argv
         tlp!(launchpad, mx_cvt(launchpad_arguments(launchpad, self.argv.len() as i32 - 1,
-                                                self.argv.as_ptr())));
+                                                   self.argv.as_ptr())));
         // Setup the environment vars
-        let status = launchpad_environ(launchpad, envp);
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
-        let status = launchpad_add_vdso_vmo(launchpad);
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
-        let status = launchpad_clone_mxio_root(launchpad);
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
+        tlp!(launchpad, mx_cvt(launchpad_environ(launchpad, envp)));
+        tlp!(launchpad, mx_cvt(launchpad_add_vdso_vmo(launchpad)));
+        tlp!(launchpad, mx_cvt(launchpad_clone_mxio_root(launchpad)));
         // Load the executable
-        let status = launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.argv[0]));
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
-        let status = launchpad_load_vdso(launchpad, MX_HANDLE_INVALID);
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
-        let status = launchpad_clone_mxio_cwd(launchpad);
-        if status != NO_ERROR {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
+        tlp!(launchpad,
+             mx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.argv[0]))));
+        tlp!(launchpad, mx_cvt(launchpad_load_vdso(launchpad, MX_HANDLE_INVALID)));
+        tlp!(launchpad, mx_cvt(launchpad_clone_mxio_cwd(launchpad)));
 
         // Clone stdin, stdout, and stderr
         if let Some(fd) = stdio.stdin.fd() {
@@ -542,17 +503,20 @@ impl Command {
             launchpad_clone_fd(launchpad, 2, 2);
         }
 
+        // We don't want FileDesc::drop to be called on any stdio. It would close their fds. The
+        // fds will be closed once the child process finishes.
+        let ChildPipes { stdin: child_stdin, stdout: child_stdout, stderr: child_stderr } = stdio;
+        if let ChildStdio::Owned(fd) = child_stdin { fd.into_raw(); }
+        if let ChildStdio::Owned(fd) = child_stdout { fd.into_raw(); }
+        if let ChildStdio::Owned(fd) = child_stderr { fd.into_raw(); }
+
         for callback in self.closures.iter_mut() {
-            t!(callback());
+            callback()?;
         }
 
-        let process_handle = launchpad_start(launchpad);
-        if process_handle < 0 {
-            launchpad_destroy(launchpad);
-            return (None, io::Error::last_os_error());
-        }
+        let process_handle = tlp!(launchpad, mx_cvt(launchpad_start(launchpad)));
 
-        (Some((launchpad, process_handle)), io::Error::last_os_error())
+        Ok((launchpad, process_handle))
     }
 
     fn setup_io(&self, default: Stdio, needs_stdin: bool)