diff --git a/src/builtins/job_control.rs b/src/builtins/job_control.rs index af0aea9d248100ce2812a7d66a247b0ae6b3198f..a5da24e137e7b0612d90bcbf121baa1968884cdc 100644 --- a/src/builtins/job_control.rs +++ b/src/builtins/job_control.rs @@ -18,6 +18,30 @@ pub fn set_foreground(pid: u32) { // TODO } +#[cfg(all(unix, not(target_os = "redox")))] +/// Suspends a given process by it's process ID. +fn suspend(pid: u32) { + let _ = signal::kill(-(pid as pid_t), Some(NixSignal::SIGTSTP)); +} + +#[cfg(all(unix, not(target_os = "redox")))] +/// Resumes a given process by it's process ID. +fn resume(pid: u32) { + let _ = signal::kill(-(pid as pid_t), Some(NixSignal::SIGCONT)); +} + +#[cfg(target_os = "redox")] +fn suspend(pid: u32) { + use syscall; + let _ = syscall::kill(pid as usize, syscall::SIGSTOP); +} + +#[cfg(target_os = "redox")] +fn resume(pid: u32) { + use syscall; + let _ = syscall::kill(pid as usize, syscall::SIGCONT); +} + /// Display a list of all jobs running in the background. pub fn jobs(shell: &mut Shell) { let stderr = stderr(); @@ -30,7 +54,6 @@ pub fn jobs(shell: &mut Shell) { } } -#[cfg(all(unix, not(target_os = "redox")))] pub fn fg(shell: &mut Shell, args: &[&str]) -> i32 { let mut status = 0; for arg in args { @@ -52,7 +75,7 @@ pub fn fg(shell: &mut Shell, args: &[&str]) -> i32 { status = shell.watch_foreground(njob) }, ProcessState::Stopped => { - let _ = signal::kill(-(job.pid as i32), Some(Signal::SIGCONT)); + resume(job.pid); set_foreground(njob); // TODO: This doesn't work status = shell.watch_foreground(njob); @@ -71,15 +94,6 @@ pub fn fg(shell: &mut Shell, args: &[&str]) -> i32 { status } -#[cfg(target_os = "redox")] -pub fn fg(_: &mut Shell, _: &[&str]) -> i32 { - let stderr = stderr(); - // TODO: Redox signal handling support - let _ = writeln!(stderr.lock(), "Redox does not yet support signals"); - 0 -} - -#[cfg(all(unix, not(target_os = "redox")))] pub fn bg(shell: &mut Shell, args: &[&str]) -> i32 { let mut error = false; let stderr = stderr(); @@ -93,7 +107,7 @@ pub fn bg(shell: &mut Shell, args: &[&str]) -> i32 { error = true; }, ProcessState::Stopped => { - let _ = signal::kill(-(job.pid as i32), Some(Signal::SIGCONT)); + resume(job.pid); job.state = ProcessState::Running; let _ = writeln!(stderr, "[{}] {} Running", njob, job.pid); }, @@ -113,11 +127,3 @@ pub fn bg(shell: &mut Shell, args: &[&str]) -> i32 { } if error { FAILURE } else { SUCCESS } } - -#[cfg(target_os = "redox")] -pub fn bg(_: &mut Shell, _: &[&str]) -> i32 { - let stderr = stderr(); - // TODO: Redox signal handling support - let _ = writeln!(stderr.lock(), "Redox does not yet support signals"); - 0 -} diff --git a/src/shell/job_control.rs b/src/shell/job_control.rs index dd88ffa742086d65e01155285b93da223ce42e68..1dfa4df15f793b6b52938c4e8ce46d43eb6c8326 100644 --- a/src/shell/job_control.rs +++ b/src/shell/job_control.rs @@ -9,7 +9,6 @@ use super::status::*; use super::Shell; pub trait JobControl { - fn suspend(&mut self, pid: u32); fn wait_for_background(&mut self); fn handle_signal(&self, signal: i32); fn foreground_send(&self, signal: i32); @@ -122,17 +121,6 @@ pub struct BackgroundProcess { } impl<'a> JobControl for Shell<'a> { - #[cfg(all(unix, not(target_os = "redox")))] - /// Suspends a given process by it's process ID. - fn suspend(&mut self, pid: u32) { - let _ = signal::kill(-(pid as pid_t), Some(NixSignal::SIGTSTP)); - } - - #[cfg(target_os = "redox")] - fn suspend(&mut self, _: u32) { - // TODO: Redox doesn't support signals yet. - } - #[cfg(all(unix, not(target_os = "redox")))] /// Waits until all running background tasks have completed, and listens for signals in the /// event that a signal is sent to kill the running tasks.