From b1c433e91af8955b7de86cdf3a0671411523ea63 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Thu, 6 Jul 2017 21:08:44 -0600 Subject: [PATCH] Fixes for Redox build --- src/shell/job_control.rs | 17 ++++++++++++----- src/shell/pipe.rs | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/shell/job_control.rs b/src/shell/job_control.rs index dde18351..dd88ffa7 100644 --- a/src/shell/job_control.rs +++ b/src/shell/job_control.rs @@ -194,9 +194,18 @@ impl<'a> JobControl for Shell<'a> { #[cfg(target_os = "redox")] fn watch_foreground(&mut self, pid: u32) -> i32 { + use std::io::{self, Write}; + use std::os::unix::process::ExitStatusExt; + use std::process::ExitStatus; + use syscall; + use syscall::flag::WNOHANG; + loop { - match child.try_wait() { - Ok(Some(status)) => { + let mut status_raw = 0; + match syscall::waitpid(pid as usize, &mut status_raw, WNOHANG) { + Ok(0) => (), + Ok(_pid) => { + let status = ExitStatus::from_raw(status_raw as i32); if let Some(code) = status.code() { break code } else { @@ -206,9 +215,6 @@ impl<'a> JobControl for Shell<'a> { break TERMINATED } }, - Ok(None) => { - thread::sleep(Duration::from_millis(1)); - }, Err(err) => { let stderr = io::stderr(); let mut stderr = stderr.lock(); @@ -216,6 +222,7 @@ impl<'a> JobControl for Shell<'a> { break 100 // TODO what should we return here? } } + sleep(Duration::from_millis(1)); } } diff --git a/src/shell/pipe.rs b/src/shell/pipe.rs index 7f58c8b8..b741f6a3 100644 --- a/src/shell/pipe.rs +++ b/src/shell/pipe.rs @@ -140,7 +140,7 @@ mod crossplat { } pub fn get_pid() -> u32 { - // TODO + syscall::getpid().unwrap() as u32 } #[derive(Debug)] @@ -272,7 +272,7 @@ enum Fork { fn ion_fork() -> syscall::error::Result<Fork> { use syscall::call::clone; unsafe { - syscall::call::clone(0).map(|pid| { + clone(0).map(|pid| { if pid == 0 { Fork::Child } else { Fork::Parent(pid as u32) } }) } @@ -412,7 +412,7 @@ fn terminate_fg(shell: &mut Shell) { #[cfg(target_os = "redox")] fn terminate_fg(shell: &mut Shell) { - // TODO: Redox does not support signals + shell.foreground_send(syscall::SIGTERM as i32); } fn execute_command(shell: &mut Shell, command: &mut Command, foreground: bool) -> i32 { -- GitLab