Improve sys_wait and replace CR with LF

master
Jiajie Chen 6 years ago
parent 6e7dc9e349
commit 8809c6ca7f

@ -13,16 +13,28 @@ pub fn sys_fork(tf: &TrapFrame) -> SysResult {
/// Wait the process exit.
/// Return the PID. Store exit code to `code` if it's not null.
pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult {
info!("wait: pid {} code {:?}", pid, code);
if !code.is_null() {
process().memory_set.check_mut_ptr(code)?;
}
loop {
use alloc::vec;
let wait_procs = match pid {
0 => processor().manager().get_children(thread::current().id()),
_ => vec![pid],
// check if pid is a child
_ => {
if processor().manager().get_children(thread::current().id()).iter()
.find(|p| **p == pid).is_some() {
vec![pid]
} else {
vec![]
}
}
};
if wait_procs.is_empty() {
return Ok(-1);
return Err(SysError::ECHILD);
}
for pid in wait_procs {
match processor().manager().get_status(pid) {
Some(Status::Exited(exit_code)) => {
@ -31,7 +43,7 @@ pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult {
}
processor().manager().remove(pid);
info!("wait: {} -> {}", thread::current().id(), pid);
return Ok(0);
return Ok(pid as isize);
}
None => return Ok(-1),
_ => {}

@ -27,5 +27,10 @@ pub fn error(tf: &TrapFrame) -> ! {
}
pub fn serial(c: char) {
if c == '\r' {
// in linux, we use '\n' instead
crate::fs::STDIN.push('\n');
} else {
crate::fs::STDIN.push(c);
}
}
Loading…
Cancel
Save