Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Redox watch_foreground #536

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions src/sys/redox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ pub mod job_control {

use shell::Shell;
use shell::foreground::ForegroundSignals;
use shell::status::TERMINATED;
use std::io::{self, Write};
use shell::status::{FAILURE, TERMINATED};
use std::os::unix::process::ExitStatusExt;
use std::process::ExitStatus;
use std::sync::{Arc, Mutex};
Expand All @@ -122,35 +121,53 @@ pub mod job_control {


pub fn watch_foreground<'a, F, D>(
_shell: &mut Shell<'a>,
pid: u32,
_last_pid: u32,
shell: &mut Shell<'a>,
_pid: u32,
last_pid: u32,
_get_command: F,
mut _drop_command: D,
mut drop_command: D,
) -> i32
where F: FnOnce() -> String,
D: FnMut(i32)
{
let mut exit_status = 0;
loop {
let mut status_raw = 0;
match syscall::waitpid(pid as usize, &mut status_raw, 0) {
Ok(0) => (),
Ok(_pid) => {
match syscall::waitpid(0, &mut status_raw, 0) {
Ok(pid) => {
let status = ExitStatus::from_raw(status_raw as i32);
if let Some(code) = status.code() {
break code;
if pid == (last_pid as usize) {
break code;
} else {
drop_command(pid as i32);
exit_status = code;
}
} else if let Some(signal) = status.signal() {
eprintln!("ion: process ended by signal: {}", signal);
if signal == syscall::SIGTERM as i32 {
shell.handle_signal(signal);
shell.exit(TERMINATED);
} else if signal == syscall::SIGHUP as i32 {
shell.handle_signal(signal);
shell.exit(TERMINATED);
} else if signal == syscall::SIGINT as i32 {
shell.foreground_send(signal);
shell.break_flow = true;
}
break TERMINATED;
} else {
let stderr = io::stderr();
let mut stderr = stderr.lock();
let _ = stderr.write_all(b"ion: child ended by signal\n");
eprintln!("ion: process ended with unknown status: {}", status);
break TERMINATED;
}
}
Err(err) => {
let stderr = io::stderr();
let mut stderr = stderr.lock();
let _ = writeln!(stderr, "ion: failed to wait: {}", err);
break 100; // TODO what should we return here?
if err.errno == syscall::ECHILD {
break exit_status;
} else {
eprintln!("ion: process doesn't exist: {}", err);
break FAILURE;
}
}
}
}
Expand Down