From a90850995f9f177c910ba548f1a6312353673926 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 10 Nov 2016 19:33:59 -0700 Subject: [PATCH] Fixes for stdio and processes on Redox --- src/libpanic_abort/lib.rs | 4 ++-- src/libpanic_unwind/lib.rs | 1 + src/libstd/io/stdio.rs | 6 ++++++ src/libstd/sys/redox/fd.rs | 3 +-- src/libstd/sys/redox/process.rs | 16 +++++++++++++++- src/libstd/sys/redox/stdio.rs | 14 +++++++++++++- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs index b87160dd75d..26bc46931bd 100644 --- a/src/libpanic_abort/lib.rs +++ b/src/libpanic_abort/lib.rs @@ -28,7 +28,7 @@ #![panic_runtime] #![feature(panic_runtime)] #![cfg_attr(unix, feature(libc))] -#![cfg_attr(windows, feature(core_intrinsics))] +#![cfg_attr(any(target_os = "redox", windows), feature(core_intrinsics))] // Rust's "try" function, but if we're aborting on panics we just call the // function as there's nothing else we need to do here. @@ -61,7 +61,7 @@ pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 { libc::abort(); } - #[cfg(windows)] + #[cfg(any(target_os = "redox", windows))] unsafe fn abort() -> ! { core::intrinsics::abort(); } diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index ff483fa823e..b75d9ec6520 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -69,6 +69,7 @@ mod imp; // i686-pc-windows-gnu and all others #[cfg(any(all(unix, not(target_os = "emscripten")), + target_os = "redox", all(windows, target_arch = "x86", target_env = "gnu")))] #[path = "gcc.rs"] mod imp; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 1777b79ea1b..27bc5f0890c 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -81,11 +81,17 @@ impl Read for StdinRaw { } impl Write for StdoutRaw { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } + #[cfg(not(target_os = "redox"))] fn flush(&mut self) -> io::Result<()> { Ok(()) } + #[cfg(target_os = "redox")] + fn flush(&mut self) -> io::Result<()> { self.0.flush() } } impl Write for StderrRaw { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } + #[cfg(not(target_os = "redox"))] fn flush(&mut self) -> io::Result<()> { Ok(()) } + #[cfg(target_os = "redox")] + fn flush(&mut self) -> io::Result<()> { self.0.flush() } } enum Maybe { diff --git a/src/libstd/sys/redox/fd.rs b/src/libstd/sys/redox/fd.rs index 9c50c547965..786d7676612 100644 --- a/src/libstd/sys/redox/fd.rs +++ b/src/libstd/sys/redox/fd.rs @@ -50,8 +50,7 @@ impl FileDesc { pub fn set_cloexec(&self) -> io::Result<()> { ::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd)); - //unimplemented!(); - Ok(()) + unimplemented!(); } pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index ad50d1de283..934cf20bf07 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -264,7 +264,21 @@ impl Command { env::set_var(key, val); } - if let Err(err) = libc::exec(&self.program, &args) { + let program = if self.program.contains(':') || self.program.contains('/') { + self.program.to_owned() + } else { + let mut path_env = ::env::var("PATH").unwrap_or(".".to_string()); + + if ! path_env.ends_with('/') { + path_env.push('/'); + } + + path_env.push_str(&self.program); + + path_env + }; + + if let Err(err) = libc::exec(&program, &args) { io::Error::from_raw_os_error(err.errno as i32) } else { panic!("return from exec without err"); diff --git a/src/libstd/sys/redox/stdio.rs b/src/libstd/sys/redox/stdio.rs index f0a781b4383..50062186903 100644 --- a/src/libstd/sys/redox/stdio.rs +++ b/src/libstd/sys/redox/stdio.rs @@ -10,6 +10,7 @@ use io; use libc; +use sys::cvt; use sys::fd::FileDesc; pub struct Stdin(()); @@ -43,6 +44,10 @@ impl Stdout { fd.into_raw(); ret } + + pub fn flush(&self) -> io::Result<()> { + cvt(libc::fsync(libc::STDOUT_FILENO)).and(Ok(())) + } } impl Stderr { @@ -54,6 +59,10 @@ impl Stderr { fd.into_raw(); ret } + + pub fn flush(&self) -> io::Result<()> { + cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(())) + } } // FIXME: right now this raw stderr handle is used in a few places because @@ -63,7 +72,10 @@ impl io::Write for Stderr { fn write(&mut self, data: &[u8]) -> io::Result { Stderr::write(self, data) } - fn flush(&mut self) -> io::Result<()> { Ok(()) } + + fn flush(&mut self) -> io::Result<()> { + cvt(libc::fsync(libc::STDERR_FILENO)).and(Ok(())) + } } pub const EBADF_ERR: i32 = ::libc::EBADF;