fix wait4 not removing child

This commit is contained in:
WangRunji 2019-04-23 14:00:44 +08:00
parent 0437e81f36
commit f846ba11f2
2 changed files with 9 additions and 9 deletions

@ -20,8 +20,7 @@ pub fn do_exit(exit_status: i32) {
current.status = Status::ZOMBIE;
// Update children
for child_weak in &current.children {
let child_ref = child_weak.upgrade().unwrap();
for child_ref in current.get_children_iter() {
let mut child = child_ref.lock().unwrap();
child.parent = Some(IDLE_PROCESS.clone());
}
@ -69,8 +68,7 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
let mut current = current_ref.lock().unwrap();
let mut any_child_to_wait_for = false;
for child_weak in current.get_children() {
let child_ref = child_weak.upgrade().unwrap();
for child_ref in current.get_children_iter() {
let child = child_ref.lock().unwrap();
let may_wait_for = match child_filter {
@ -82,8 +80,9 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
continue;
}
// Return immediately as a child that we wait for has alreay exited
// Return immediately as a child that we wait for has already exited
if child.status == Status::ZOMBIE {
process_table::remove(child.pid);
return Ok(child.pid);
}
@ -107,8 +106,7 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
let mut current = current_ref.lock().unwrap();
let child_i = {
let mut child_i_opt = None;
for (child_i, child_weak) in current.children.iter().enumerate() {
let child_ref = child_weak.upgrade().unwrap();
for (child_i, child_ref) in current.get_children_iter().enumerate() {
let child = child_ref.lock().unwrap();
if child.get_pid() != child_pid {
continue;

@ -88,8 +88,10 @@ impl Process {
pub fn get_parent(&self) -> &ProcessRef {
self.parent.as_ref().unwrap()
}
pub fn get_children(&self) -> &[ProcessWeakRef] {
&self.children
pub fn get_children_iter(&self) -> impl Iterator<Item=ProcessRef> + '_ {
self.children
.iter()
.filter_map(|child_weak| child_weak.upgrade())
}
pub fn change_cwd(&mut self, path: &str) {
if path.len() > 0 && path.as_bytes()[0] == b'/' {