From 2cde3b54ca2bf0da62fb59fc47b5d0a45d1e57cb Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy <mmstickman@gmail.com> Date: Sun, 31 Dec 2017 14:04:06 -0500 Subject: [PATCH] Remove foreground field from shell --- src/lib/shell/mod.rs | 4 ---- src/lib/shell/pipe_exec/job_control.rs | 8 -------- src/lib/shell/pipe_exec/mod.rs | 7 ------- src/lib/sys/redox.rs | 6 ++++-- src/lib/sys/unix/job_control.rs | 3 +-- 5 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs index 1ca66d6d..3a7522e8 100644 --- a/src/lib/shell/mod.rs +++ b/src/lib/shell/mod.rs @@ -84,9 +84,6 @@ pub struct Shell { pub(crate) previous_job: u32, /// Contains all the boolean flags that control shell behavior. pub flags: u8, - /// A temporary field for storing foreground PIDs used by the pipeline - /// execution. - foreground: Vec<u32>, /// Contains information on all of the active background processes that are being managed /// by the shell. pub(crate) background: Arc<Mutex<Vec<BackgroundProcess>>>, @@ -170,7 +167,6 @@ impl<'a> Shell { previous_job: !0, previous_status: 0, flags: 0, - foreground: Vec::new(), background: Arc::new(Mutex::new(Vec::new())), is_background_shell: false, is_library, diff --git a/src/lib/shell/pipe_exec/job_control.rs b/src/lib/shell/pipe_exec/job_control.rs index 854fd97a..5fcd3d08 100644 --- a/src/lib/shell/pipe_exec/job_control.rs +++ b/src/lib/shell/pipe_exec/job_control.rs @@ -31,7 +31,6 @@ pub(crate) trait JobControl { fn set_bg_task_in_foreground(&self, pid: u32, cont: bool) -> i32; fn resume_stopped(&mut self); fn handle_signal(&self, signal: i32) -> bool; - fn foreground_send(&self, signal: i32); fn background_send(&self, signal: i32); fn watch_foreground(&mut self, pid: i32, command: &str) -> i32; fn send_to_background(&mut self, child: u32, state: ProcessState, command: String); @@ -152,13 +151,6 @@ impl JobControl for Shell { self_sys::watch_foreground(self, pid, command) } - /// Send a kill signal to all running foreground tasks. - fn foreground_send(&self, signal: i32) { - for &process in self.foreground.iter() { - let _ = sys::killpg(process, signal); - } - } - /// Resumes all stopped background jobs fn resume_stopped(&mut self) { for process in self.background.lock().unwrap().iter() { diff --git a/src/lib/shell/pipe_exec/mod.rs b/src/lib/shell/pipe_exec/mod.rs index 087b9637..36c52326 100644 --- a/src/lib/shell/pipe_exec/mod.rs +++ b/src/lib/shell/pipe_exec/mod.rs @@ -414,8 +414,6 @@ pub(crate) trait PipelineExecution { impl PipelineExecution for Shell { fn execute_pipeline(&mut self, pipeline: &mut Pipeline) -> i32 { - // Remove any leftover foreground tasks from the last execution. - self.foreground.clear(); // If the supplied pipeline is a background, a string representing the command // and a boolean representing whether it should be disowned is stored here. let possible_background_name = @@ -1002,7 +1000,6 @@ fn spawn_proc( close(stdin); close(stdout); close(stderr); - shell.foreground.push(pid); *last_pid = *current_pid; *current_pid = pid; }, @@ -1025,7 +1022,6 @@ fn spawn_proc( Ok(pid) => { close(stdout); close(stderr); - shell.foreground.push(pid); *last_pid = *current_pid; *current_pid = pid; }, @@ -1048,7 +1044,6 @@ fn spawn_proc( Ok(pid) => { close(stdout); close(stderr); - shell.foreground.push(pid); *last_pid = *current_pid; *current_pid = pid; }, @@ -1069,7 +1064,6 @@ fn spawn_proc( } Ok(pid) => { close(stdout); - shell.foreground.push(pid); *last_pid = *current_pid; *current_pid = pid; } @@ -1090,7 +1084,6 @@ fn spawn_proc( Ok(pid) => { close(stdout); close(stderr); - shell.foreground.push(pid); *last_pid = *current_pid; *current_pid = pid; } diff --git a/src/lib/sys/redox.rs b/src/lib/sys/redox.rs index 1b19fd5a..3889d783 100644 --- a/src/lib/sys/redox.rs +++ b/src/lib/sys/redox.rs @@ -234,9 +234,11 @@ pub mod job_control { } } + let pid = get_pid_value(pid); + loop { status = 0; - let result = waitpid(get_pid_value(pid), &mut status, 0); + let result = waitpid(pid, &mut status, 0); match result { Err(error) => { match error.errno { @@ -257,7 +259,7 @@ pub mod job_control { eprintln!("ion: process ended by signal {}", signal); match signal { SIGINT => { - shell.foreground_send(signal as i32); + let _ = syscall::kill(pid, signal as usize); shell.break_flow = true; } _ => { diff --git a/src/lib/sys/unix/job_control.rs b/src/lib/sys/unix/job_control.rs index 3343fa6f..fdfc879e 100644 --- a/src/lib/sys/unix/job_control.rs +++ b/src/lib/sys/unix/job_control.rs @@ -6,7 +6,6 @@ use shell::status::{FAILURE, TERMINATED}; use std::sync::{Arc, Mutex}; use std::thread::sleep; use std::time::Duration; -use std::io; use super::{errno, write_errno}; pub(crate) fn watch_background( @@ -108,7 +107,7 @@ pub(crate) fn watch_foreground(shell: &mut Shell, pid: i32, command: &str) -> i3 eprintln!("ion: process ended by signal {}", signal); match signal { SIGINT => { - shell.foreground_send(signal as i32); + let _ = kill(pid, signal as i32); shell.break_flow = true; } _ => { -- GitLab