diff --git a/src/shell/job_control.rs b/src/shell/job_control.rs index dde18351ba1ee17b45a97f48aa191d5c340708ff..dd88ffa742086d65e01155285b93da223ce42e68 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 7f58c8b82b8aa14f4ec7fe334aa407627586f140..b741f6a38607f5c55ed85b9a66ce347c734e5304 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 {