Skip to content

Commit fae86b9

Browse files
committed
Cleaned up and appeased the linter
1 parent 5c23f2e commit fae86b9

File tree

3 files changed

+30
-77
lines changed

3 files changed

+30
-77
lines changed

src/libstd/process.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,6 @@ impl Child {
780780
///
781781
#[stable(feature = "process", since = "1.0.0")]
782782
pub fn wait_with_output(mut self) -> io::Result<Output> {
783-
//use io::ErrorKind;
784-
785783
drop(self.stdin.take());
786784

787785
let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
@@ -796,15 +794,8 @@ impl Child {
796794
res.unwrap();
797795
}
798796
(Some(out), Some(err)) => {
799-
match read2(out.inner, &mut stdout, err.inner, &mut stderr) {
800-
Ok(()) => { },
801-
#[cfg(not(target_os = "fuchsia"))]
802-
Err(ref e) => { panic!("Failed to read child's stdout and stderr: {:?}", e); },
803-
#[cfg(target_os = "fuchsia")]
804-
Err(_) => {
805-
// FIXME: Right now there's a bug in magenta's pipes implementation
806-
},
807-
}
797+
let res = read2(out.inner, &mut stdout, err.inner, &mut stderr);
798+
res.update();
808799
}
809800
}
810801

src/libstd/sys/unix/magenta.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ pub const MX_HANDLE_INVALID: mx_handle_t = 0;
2828
pub type mx_time_t = u64;
2929
pub const MX_TIME_INFINITE : mx_time_t = u64::MAX;
3030

31-
pub const NO_ERROR : mx_status_t = 0;
32-
3331
pub type mx_signals_t = u32;
3432

3533
pub const MX_OBJECT_SIGNAL_3 : mx_signals_t = 1 << 3;

src/libstd/sys/unix/process.rs

Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,9 @@ impl Command {
309309

310310
let (ours, theirs) = self.setup_io(default, needs_stdin)?;
311311

312-
let (maybe_process, err) = unsafe { self.do_exec(&theirs) };
313-
// We don't want FileDesc::drop to be called on any stdio. It would close their handles.
314-
let ChildPipes { stdin: their_stdin, stdout: their_stdout, stderr: their_stderr } = theirs;
315-
their_stdin.fd();
316-
their_stdout.fd();
317-
their_stderr.fd();
318-
319-
if let Some((launchpad, process_handle)) = maybe_process {
320-
Ok((Process { launchpad: launchpad, handle: process_handle, status: None }, ours))
321-
} else {
322-
Err(err)
323-
}
312+
let (launchpad, process_handle) = unsafe { self.do_exec(theirs)? };
313+
314+
Ok((Process { launchpad: launchpad, handle: process_handle, status: None }, ours))
324315
}
325316

326317
#[cfg(not(target_os = "fuchsia"))]
@@ -453,23 +444,16 @@ impl Command {
453444
}
454445

455446
#[cfg(target_os = "fuchsia")]
456-
unsafe fn do_exec(&mut self, stdio: &ChildPipes)
457-
-> (Option<(*mut launchpad_t, mx_handle_t)>, io::Error) {
447+
unsafe fn do_exec(&mut self, stdio: ChildPipes)
448+
-> io::Result<(*mut launchpad_t, mx_handle_t)> {
458449
use sys::magenta::*;
459450

460-
macro_rules! t {
461-
($e:expr) => (match $e {
462-
Ok(e) => e,
463-
Err(e) => return (None, e),
464-
})
465-
}
466-
467451
macro_rules! tlp {
468452
($lp:expr, $e:expr) => (match $e {
469453
Ok(e) => e,
470454
Err(e) => {
471455
launchpad_destroy($lp);
472-
return (None, e);
456+
return Err(e);
473457
},
474458
})
475459
}
@@ -484,46 +468,23 @@ impl Command {
484468
let mut job_copy: mx_handle_t = MX_HANDLE_INVALID;
485469

486470
// Duplicate the job handle
487-
t!(mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS,
488-
&mut job_copy as *mut mx_handle_t)));
471+
mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS,
472+
&mut job_copy as *mut mx_handle_t))?;
489473
// Create a launchpad
490-
t!(mx_cvt(launchpad_create(job_copy, self.argv[0],
491-
&mut launchpad as *mut *mut launchpad_t)));
474+
mx_cvt(launchpad_create(job_copy, self.argv[0],
475+
&mut launchpad as *mut *mut launchpad_t))?;
492476
// Set the process argv
493477
tlp!(launchpad, mx_cvt(launchpad_arguments(launchpad, self.argv.len() as i32 - 1,
494-
self.argv.as_ptr())));
478+
self.argv.as_ptr())));
495479
// Setup the environment vars
496-
let status = launchpad_environ(launchpad, envp);
497-
if status != NO_ERROR {
498-
launchpad_destroy(launchpad);
499-
return (None, io::Error::last_os_error());
500-
}
501-
let status = launchpad_add_vdso_vmo(launchpad);
502-
if status != NO_ERROR {
503-
launchpad_destroy(launchpad);
504-
return (None, io::Error::last_os_error());
505-
}
506-
let status = launchpad_clone_mxio_root(launchpad);
507-
if status != NO_ERROR {
508-
launchpad_destroy(launchpad);
509-
return (None, io::Error::last_os_error());
510-
}
480+
tlp!(launchpad, mx_cvt(launchpad_environ(launchpad, envp)));
481+
tlp!(launchpad, mx_cvt(launchpad_add_vdso_vmo(launchpad)));
482+
tlp!(launchpad, mx_cvt(launchpad_clone_mxio_root(launchpad)));
511483
// Load the executable
512-
let status = launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.argv[0]));
513-
if status != NO_ERROR {
514-
launchpad_destroy(launchpad);
515-
return (None, io::Error::last_os_error());
516-
}
517-
let status = launchpad_load_vdso(launchpad, MX_HANDLE_INVALID);
518-
if status != NO_ERROR {
519-
launchpad_destroy(launchpad);
520-
return (None, io::Error::last_os_error());
521-
}
522-
let status = launchpad_clone_mxio_cwd(launchpad);
523-
if status != NO_ERROR {
524-
launchpad_destroy(launchpad);
525-
return (None, io::Error::last_os_error());
526-
}
484+
tlp!(launchpad,
485+
mx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.argv[0]))));
486+
tlp!(launchpad, mx_cvt(launchpad_load_vdso(launchpad, MX_HANDLE_INVALID)));
487+
tlp!(launchpad, mx_cvt(launchpad_clone_mxio_cwd(launchpad)));
527488

528489
// Clone stdin, stdout, and stderr
529490
if let Some(fd) = stdio.stdin.fd() {
@@ -542,17 +503,20 @@ impl Command {
542503
launchpad_clone_fd(launchpad, 2, 2);
543504
}
544505

506+
// We don't want FileDesc::drop to be called on any stdio. It would close their fds. The
507+
// fds will be closed once the child process finishes.
508+
let ChildPipes { stdin: child_stdin, stdout: child_stdout, stderr: child_stderr } = stdio;
509+
if let ChildStdio::Owned(fd) = child_stdin { fd.into_raw(); }
510+
if let ChildStdio::Owned(fd) = child_stdout { fd.into_raw(); }
511+
if let ChildStdio::Owned(fd) = child_stderr { fd.into_raw(); }
512+
545513
for callback in self.closures.iter_mut() {
546-
t!(callback());
514+
callback()?;
547515
}
548516

549-
let process_handle = launchpad_start(launchpad);
550-
if process_handle < 0 {
551-
launchpad_destroy(launchpad);
552-
return (None, io::Error::last_os_error());
553-
}
517+
let process_handle = tlp!(launchpad, mx_cvt(launchpad_start(launchpad)));
554518

555-
(Some((launchpad, process_handle)), io::Error::last_os_error())
519+
Ok((launchpad, process_handle))
556520
}
557521

558522
fn setup_io(&self, default: Stdio, needs_stdin: bool)

0 commit comments

Comments
 (0)