Fixes for building with Redox in the unix target family

This commit is contained in:
Jeremy Soller
2019-04-23 13:45:20 -06:00
parent f5ff59f085
commit 396750c2da
2 changed files with 9 additions and 7 deletions
Generated
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "init"
version = "0.1.0"
+7 -7
View File
@@ -5,25 +5,25 @@ extern crate syscall;
use std::env;
use std::fs::{File, read_dir};
use std::io::{Read, Error, Result};
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::path::Path;
use std::process::Command;
use syscall::flag::{O_RDONLY, O_WRONLY};
fn switch_stdio(stdio: &str) -> Result<()> {
let stdin = unsafe { File::from_raw_fd(
syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd
) };
let stdout = unsafe { File::from_raw_fd(
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd
) };
let stderr = unsafe { File::from_raw_fd(
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))? as RawFd
) };
syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stdout.as_raw_fd(), 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stderr.as_raw_fd(), 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stdin.as_raw_fd() as usize, 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stdout.as_raw_fd() as usize, 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stderr.as_raw_fd() as usize, 2, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
Ok(())
}