Skip to content

Commit e1b752b

Browse files
committed
std::process fuchsia support cleanup
1 parent 8d9d07a commit e1b752b

File tree

5 files changed

+26
-34
lines changed

5 files changed

+26
-34
lines changed

src/libstd/sys/unix/mod.rs

-20
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
use io::{self, ErrorKind};
1414
use libc;
1515

16-
#[cfg(target_os = "fuchsia")]
17-
use convert::TryInto;
18-
#[cfg(target_os = "fuchsia")]
19-
pub use self::magenta::mx_status_t;
20-
2116
#[cfg(target_os = "android")] pub use os::android as platform;
2217
#[cfg(target_os = "bitrig")] pub use os::bitrig as platform;
2318
#[cfg(target_os = "dragonfly")] pub use os::dragonfly as platform;
@@ -46,8 +41,6 @@ pub mod ext;
4641
pub mod fast_thread_local;
4742
pub mod fd;
4843
pub mod fs;
49-
#[cfg(target_os = "fuchsia")]
50-
pub mod magenta;
5144
pub mod memchr;
5245
pub mod mutex;
5346
pub mod net;
@@ -171,19 +164,6 @@ pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
171164
}
172165
}
173166

174-
#[cfg(target_os = "fuchsia")]
175-
pub fn mx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<mx_status_t>+Copy {
176-
if let Ok(status) = TryInto::try_into(t) {
177-
if status < 0 {
178-
Err(io::Error::from_raw_os_error(status))
179-
} else {
180-
Ok(t)
181-
}
182-
} else {
183-
Err(io::Error::last_os_error())
184-
}
185-
}
186-
187167
// On Unix-like platforms, libc::abort will unregister signal handlers
188168
// including the SIGABRT handler, preventing the abort from being blocked, and
189169
// fclose streams, with the side effect of flushing them so libc bufferred

src/libstd/sys/unix/magenta.rs renamed to src/libstd/sys/unix/process/magenta.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#![allow(non_camel_case_types)]
1212

13+
use convert::TryInto;
14+
use io;
1315
use os::raw::c_char;
1416
use u64;
1517

@@ -42,6 +44,18 @@ pub const MX_INFO_PROCESS : mx_object_info_topic_t = 3;
4244

4345
pub const MX_HND_TYPE_JOB: u32 = 6;
4446

47+
pub fn mx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<mx_status_t>+Copy {
48+
if let Ok(status) = TryInto::try_into(t) {
49+
if status < 0 {
50+
Err(io::Error::from_raw_os_error(status))
51+
} else {
52+
Ok(t)
53+
}
54+
} else {
55+
Err(io::Error::last_os_error())
56+
}
57+
}
58+
4559
// Safe wrapper around mx_handle_t
4660
pub struct Handle {
4761
raw: mx_handle_t,
@@ -61,7 +75,6 @@ impl Handle {
6175

6276
impl Drop for Handle {
6377
fn drop(&mut self) {
64-
use sys::mx_cvt;
6578
unsafe { mx_cvt(mx_handle_close(self.raw)).expect("Failed to close mx_handle_t"); }
6679
}
6780
}

src/libstd/sys/unix/process/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ mod process_inner;
1818
#[cfg(target_os = "fuchsia")]
1919
#[path = "process_fuchsia.rs"]
2020
mod process_inner;
21+
#[cfg(target_os = "fuchsia")]
22+
mod magenta;

src/libstd/sys/unix/process/process_common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ impl Command {
203203
&self.argv
204204
}
205205

206-
#[cfg(not(target_os="fuchsia"))]
206+
#[allow(dead_code)]
207207
pub fn get_cwd(&self) -> &Option<CString> {
208208
&self.cwd
209209
}
210-
#[cfg(not(target_os="fuchsia"))]
210+
#[allow(dead_code)]
211211
pub fn get_uid(&self) -> Option<uid_t> {
212212
self.uid
213213
}
214-
#[cfg(not(target_os="fuchsia"))]
214+
#[allow(dead_code)]
215215
pub fn get_gid(&self) -> Option<gid_t> {
216216
self.gid
217217
}

src/libstd/sys/unix/process/process_fuchsia.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use libc;
1313
use mem;
1414
use ptr;
1515

16-
use sys::mx_cvt;
17-
use sys::magenta::{Handle, launchpad_t, mx_handle_t};
16+
use sys::process::magenta::{Handle, launchpad_t, mx_handle_t};
1817
use sys::process::process_common::*;
1918

2019
////////////////////////////////////////////////////////////////////////////////
@@ -53,7 +52,7 @@ impl Command {
5352

5453
unsafe fn do_exec(&mut self, stdio: ChildPipes)
5554
-> io::Result<(*mut launchpad_t, mx_handle_t)> {
56-
use sys::magenta::*;
55+
use sys::process::magenta::*;
5756

5857
let job_handle = mxio_get_startup_handle(mx_hnd_info(MX_HND_TYPE_JOB, 0));
5958
let envp = match *self.get_envp() {
@@ -72,11 +71,9 @@ impl Command {
7271

7372
// Duplicate the job handle
7473
let mut job_copy: mx_handle_t = MX_HANDLE_INVALID;
75-
mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS,
76-
&mut job_copy as *mut mx_handle_t))?;
74+
mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS, &mut job_copy))?;
7775
// Create a launchpad
78-
mx_cvt(launchpad_create(job_copy, self.get_argv()[0],
79-
&mut launchpad as *mut *mut launchpad_t))?;
76+
mx_cvt(launchpad_create(job_copy, self.get_argv()[0], &mut launchpad))?;
8077
// Set the process argv
8178
mx_cvt(launchpad_arguments(launchpad, self.get_argv().len() as i32 - 1,
8279
self.get_argv().as_ptr()))?;
@@ -138,7 +135,7 @@ impl Process {
138135
}
139136

140137
pub fn kill(&mut self) -> io::Result<()> {
141-
use sys::magenta::*;
138+
use sys::process::magenta::*;
142139

143140
unsafe { mx_cvt(mx_task_kill(self.handle.raw()))?; }
144141

@@ -147,7 +144,7 @@ impl Process {
147144

148145
pub fn wait(&mut self) -> io::Result<ExitStatus> {
149146
use default::Default;
150-
use sys::magenta::*;
147+
use sys::process::magenta::*;
151148

152149
let mut proc_info: mx_info_process_t = Default::default();
153150
let mut actual: mx_size_t = 0;
@@ -171,7 +168,7 @@ impl Process {
171168

172169
impl Drop for Process {
173170
fn drop(&mut self) {
174-
use sys::magenta::launchpad_destroy;
171+
use sys::process::magenta::launchpad_destroy;
175172
unsafe { launchpad_destroy(self.launchpad); }
176173
}
177174
}

0 commit comments

Comments
 (0)