Skip to content

Commit

Permalink
Cleaned up and appeased the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
tedsta committed Nov 23, 2016
1 parent 5c23f2e commit fae86b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 77 deletions.
13 changes: 2 additions & 11 deletions src/libstd/process.rs
Expand Up @@ -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());
Expand All @@ -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();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/libstd/sys/unix/magenta.rs
Expand Up @@ -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;
Expand Down
92 changes: 28 additions & 64 deletions src/libstd/sys/unix/process.rs
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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);
},
})
}
Expand All @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit fae86b9

Please sign in to comment.