diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 21a259a577b8e05c25278100b6d2b1086ad89d9f..227853a8239d78ea5690f37f00de512e95c80996 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -1265,6 +1265,24 @@ pub fn waitpid(pid: ContextId, status_ptr: usize, flags: usize) -> Result<Contex loop { let res_opt = if pid.into() == 0 { + // Check for existence of child + { + let mut found = false; + + let contexts = context::contexts(); + for (_id, context_lock) in contexts.iter() { + let context = context_lock.read(); + if context.ppid == ppid { + found = true; + break; + } + } + + if ! found { + return Err(Error::new(ECHILD)); + } + } + if flags & WNOHANG == WNOHANG { if let Some((_wid, (w_pid, status))) = waitpid.receive_any_nonblock() { grim_reaper(w_pid, status) @@ -1277,7 +1295,25 @@ pub fn waitpid(pid: ContextId, status_ptr: usize, flags: usize) -> Result<Contex } } else if (pid.into() as isize) < 0 { let pgid = ContextId::from(-(pid.into() as isize) as usize); - //TODO: Check for existence of child in process group PGID + + // Check for existence of child in process group PGID + { + let mut found = false; + + let contexts = context::contexts(); + for (_id, context_lock) in contexts.iter() { + let context = context_lock.read(); + if context.pgid == pgid { + found = true; + break; + } + } + + if ! found { + return Err(Error::new(ECHILD)); + } + } + if flags & WNOHANG == WNOHANG { if let Some((w_pid, status)) = waitpid.receive_nonblock(&WaitpidKey { pid: None,