std::process fuchsia support cleanup

This commit is contained in:
Theodore DeRego 2016-12-01 12:01:07 -08:00
parent 8d9d07a1ca
commit e1b752b2a1
5 changed files with 26 additions and 34 deletions

View File

@ -13,11 +13,6 @@
use io::{self, ErrorKind};
use libc;
#[cfg(target_os = "fuchsia")]
use convert::TryInto;
#[cfg(target_os = "fuchsia")]
pub use self::magenta::mx_status_t;
#[cfg(target_os = "android")] pub use os::android as platform;
#[cfg(target_os = "bitrig")] pub use os::bitrig as platform;
#[cfg(target_os = "dragonfly")] pub use os::dragonfly as platform;
@ -46,8 +41,6 @@ pub mod ext;
pub mod fast_thread_local;
pub mod fd;
pub mod fs;
#[cfg(target_os = "fuchsia")]
pub mod magenta;
pub mod memchr;
pub mod mutex;
pub mod net;
@ -171,19 +164,6 @@ pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
}
}
#[cfg(target_os = "fuchsia")]
pub fn mx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<mx_status_t>+Copy {
if let Ok(status) = TryInto::try_into(t) {
if status < 0 {
Err(io::Error::from_raw_os_error(status))
} else {
Ok(t)
}
} else {
Err(io::Error::last_os_error())
}
}
// On Unix-like platforms, libc::abort will unregister signal handlers
// including the SIGABRT handler, preventing the abort from being blocked, and
// fclose streams, with the side effect of flushing them so libc bufferred

View File

@ -10,6 +10,8 @@
#![allow(non_camel_case_types)]
use convert::TryInto;
use io;
use os::raw::c_char;
use u64;
@ -42,6 +44,18 @@ pub const MX_INFO_PROCESS : mx_object_info_topic_t = 3;
pub const MX_HND_TYPE_JOB: u32 = 6;
pub fn mx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<mx_status_t>+Copy {
if let Ok(status) = TryInto::try_into(t) {
if status < 0 {
Err(io::Error::from_raw_os_error(status))
} else {
Ok(t)
}
} else {
Err(io::Error::last_os_error())
}
}
// Safe wrapper around mx_handle_t
pub struct Handle {
raw: mx_handle_t,
@ -61,7 +75,6 @@ impl Handle {
impl Drop for Handle {
fn drop(&mut self) {
use sys::mx_cvt;
unsafe { mx_cvt(mx_handle_close(self.raw)).expect("Failed to close mx_handle_t"); }
}
}

View File

@ -18,3 +18,5 @@ mod process_inner;
#[cfg(target_os = "fuchsia")]
#[path = "process_fuchsia.rs"]
mod process_inner;
#[cfg(target_os = "fuchsia")]
mod magenta;

View File

@ -203,15 +203,15 @@ impl Command {
&self.argv
}
#[cfg(not(target_os="fuchsia"))]
#[allow(dead_code)]
pub fn get_cwd(&self) -> &Option<CString> {
&self.cwd
}
#[cfg(not(target_os="fuchsia"))]
#[allow(dead_code)]
pub fn get_uid(&self) -> Option<uid_t> {
self.uid
}
#[cfg(not(target_os="fuchsia"))]
#[allow(dead_code)]
pub fn get_gid(&self) -> Option<gid_t> {
self.gid
}

View File

@ -13,8 +13,7 @@ use libc;
use mem;
use ptr;
use sys::mx_cvt;
use sys::magenta::{Handle, launchpad_t, mx_handle_t};
use sys::process::magenta::{Handle, launchpad_t, mx_handle_t};
use sys::process::process_common::*;
////////////////////////////////////////////////////////////////////////////////
@ -53,7 +52,7 @@ impl Command {
unsafe fn do_exec(&mut self, stdio: ChildPipes)
-> io::Result<(*mut launchpad_t, mx_handle_t)> {
use sys::magenta::*;
use sys::process::magenta::*;
let job_handle = mxio_get_startup_handle(mx_hnd_info(MX_HND_TYPE_JOB, 0));
let envp = match *self.get_envp() {
@ -72,11 +71,9 @@ impl Command {
// Duplicate the job handle
let mut job_copy: mx_handle_t = MX_HANDLE_INVALID;
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))?;
// Create a launchpad
mx_cvt(launchpad_create(job_copy, self.get_argv()[0],
&mut launchpad as *mut *mut launchpad_t))?;
mx_cvt(launchpad_create(job_copy, self.get_argv()[0], &mut launchpad))?;
// Set the process argv
mx_cvt(launchpad_arguments(launchpad, self.get_argv().len() as i32 - 1,
self.get_argv().as_ptr()))?;
@ -138,7 +135,7 @@ impl Process {
}
pub fn kill(&mut self) -> io::Result<()> {
use sys::magenta::*;
use sys::process::magenta::*;
unsafe { mx_cvt(mx_task_kill(self.handle.raw()))?; }
@ -147,7 +144,7 @@ impl Process {
pub fn wait(&mut self) -> io::Result<ExitStatus> {
use default::Default;
use sys::magenta::*;
use sys::process::magenta::*;
let mut proc_info: mx_info_process_t = Default::default();
let mut actual: mx_size_t = 0;
@ -171,7 +168,7 @@ impl Process {
impl Drop for Process {
fn drop(&mut self) {
use sys::magenta::launchpad_destroy;
use sys::process::magenta::launchpad_destroy;
unsafe { launchpad_destroy(self.launchpad); }
}
}