Skip to content
Snippets Groups Projects
Commit 2b99617a authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Background & Foreground Fixes

parent 421d1787
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,9 @@ use std::process::exit;
pub fn fork_pipe(shell: &mut Shell, commands: Vec<(RefinedJob, JobKind)>, command_name: String) -> i32 {
match unsafe { sys::fork() } {
Ok(0) => {
// The child fork should not have any signals blocked, so the shell can control it.
signals::unblock();
let _ = sys::reset_signal(sys::SIGINT);
let _ = sys::reset_signal(sys::SIGHUP);
let _ = sys::reset_signal(sys::SIGTERM);
// This ensures that the child fork has a unique PGID.
create_process_group(0);
// After execution of it's commands, exit with the last command's status.
......
......@@ -23,7 +23,6 @@ use std::os::unix::process::CommandExt;
use std::process::{exit, Command};
use sys;
/// Use dup2 to replace `old` with `new` using `old`s file descriptor ID
fn redir(old: RawFd, new: RawFd) {
if let Err(e) = sys::dup2(old, new) {
......@@ -257,6 +256,9 @@ pub fn pipe(shell: &mut Shell, commands: Vec<(RefinedJob, JobKind)>, foreground:
match unsafe { sys::fork() } {
Ok(0) => {
signals::unblock();
let _ = sys::reset_signal(sys::SIGINT);
let _ = sys::reset_signal(sys::SIGHUP);
let _ = sys::reset_signal(sys::SIGTERM);
create_process_group(pgid);
let args: Vec<&str> = args
.iter()
......
......@@ -252,7 +252,7 @@ pub mod job_control {
{
let mut exit_status = 0;
loop {
match wait() {
match waitpid(-1, Some(WUNTRACED)) {
Ok(WaitStatus::Exited(pid, status)) => if pid == (last_pid as i32) {
break status as i32;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment