Fixes for stdio and processes on Redox

This commit is contained in:
Jeremy Soller 2016-11-10 19:33:59 -07:00
parent ced32a08f3
commit a90850995f
6 changed files with 38 additions and 6 deletions

View File

@ -28,7 +28,7 @@
#![panic_runtime] #![panic_runtime]
#![feature(panic_runtime)] #![feature(panic_runtime)]
#![cfg_attr(unix, feature(libc))] #![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 // 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. // 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(); libc::abort();
} }
#[cfg(windows)] #[cfg(any(target_os = "redox", windows))]
unsafe fn abort() -> ! { unsafe fn abort() -> ! {
core::intrinsics::abort(); core::intrinsics::abort();
} }

View File

@ -69,6 +69,7 @@ mod imp;
// i686-pc-windows-gnu and all others // i686-pc-windows-gnu and all others
#[cfg(any(all(unix, not(target_os = "emscripten")), #[cfg(any(all(unix, not(target_os = "emscripten")),
target_os = "redox",
all(windows, target_arch = "x86", target_env = "gnu")))] all(windows, target_arch = "x86", target_env = "gnu")))]
#[path = "gcc.rs"] #[path = "gcc.rs"]
mod imp; mod imp;

View File

@ -81,11 +81,17 @@ impl Read for StdinRaw {
} }
impl Write for StdoutRaw { impl Write for StdoutRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) } fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
#[cfg(not(target_os = "redox"))]
fn flush(&mut self) -> io::Result<()> { Ok(()) } fn flush(&mut self) -> io::Result<()> { Ok(()) }
#[cfg(target_os = "redox")]
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
} }
impl Write for StderrRaw { impl Write for StderrRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) } fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) }
#[cfg(not(target_os = "redox"))]
fn flush(&mut self) -> io::Result<()> { Ok(()) } fn flush(&mut self) -> io::Result<()> { Ok(()) }
#[cfg(target_os = "redox")]
fn flush(&mut self) -> io::Result<()> { self.0.flush() }
} }
enum Maybe<T> { enum Maybe<T> {

View File

@ -50,8 +50,7 @@ impl FileDesc {
pub fn set_cloexec(&self) -> io::Result<()> { pub fn set_cloexec(&self) -> io::Result<()> {
::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd)); ::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd));
//unimplemented!(); unimplemented!();
Ok(())
} }
pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {

View File

@ -264,7 +264,21 @@ impl Command {
env::set_var(key, val); 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) io::Error::from_raw_os_error(err.errno as i32)
} else { } else {
panic!("return from exec without err"); panic!("return from exec without err");

View File

@ -10,6 +10,7 @@
use io; use io;
use libc; use libc;
use sys::cvt;
use sys::fd::FileDesc; use sys::fd::FileDesc;
pub struct Stdin(()); pub struct Stdin(());
@ -43,6 +44,10 @@ impl Stdout {
fd.into_raw(); fd.into_raw();
ret ret
} }
pub fn flush(&self) -> io::Result<()> {
cvt(libc::fsync(libc::STDOUT_FILENO)).and(Ok(()))
}
} }
impl Stderr { impl Stderr {
@ -54,6 +59,10 @@ impl Stderr {
fd.into_raw(); fd.into_raw();
ret 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 // 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<usize> { fn write(&mut self, data: &[u8]) -> io::Result<usize> {
Stderr::write(self, data) 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; pub const EBADF_ERR: i32 = ::libc::EBADF;