mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
syscalls: fix waitpid's behaviour
This commit is contained in:
+42
-15
@@ -37,28 +37,48 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
|||||||
|
|
||||||
proc_t* proc = arch_getcls()->thread->proc;
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
|
|
||||||
event_wait(&proc->childevent, true);
|
bool loop = true;
|
||||||
|
|
||||||
// now find the child
|
|
||||||
|
|
||||||
spinlock_acquire(&proc->lock);
|
proc_t* child;
|
||||||
proc_t* child = proc->child;
|
proc_t* sibling;
|
||||||
proc_t* sibling = NULL;
|
|
||||||
|
|
||||||
while(child){
|
while(1){
|
||||||
if(pid > 0 && child->pid != pid)
|
|
||||||
continue;
|
child = proc->child;
|
||||||
|
sibling = NULL;
|
||||||
|
|
||||||
|
// now find the child
|
||||||
|
|
||||||
|
spinlock_acquire(&proc->lock);
|
||||||
|
|
||||||
|
while(child){
|
||||||
|
if(pid > 0 && child->pid != pid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(child->state == PROC_STATE_ZOMBIE){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(child->sibling)
|
||||||
|
sibling = child;
|
||||||
|
child = child->sibling;
|
||||||
|
|
||||||
if(child->state == PROC_STATE_ZOMBIE){
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(child->sibling)
|
spinlock_release(&proc->lock);
|
||||||
sibling = child;
|
|
||||||
child = child->sibling;
|
if(loop){
|
||||||
|
event_wait(&proc->childevent, true);
|
||||||
|
loop = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!child){
|
if(!child){
|
||||||
spinlock_release(&proc->lock);
|
spinlock_release(&proc->lock);
|
||||||
retv.errno = ECHILD;
|
retv.errno = ECHILD;
|
||||||
@@ -71,10 +91,17 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
|||||||
spinlock_release(&sibling->lock);
|
spinlock_release(&sibling->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&proc->lock);
|
|
||||||
|
|
||||||
*status = child->status; // XXX safer way of doing this
|
*status = child->status; // XXX safer way of doing this
|
||||||
|
|
||||||
|
// the pointer to the last remaining thread is is proc->threads
|
||||||
|
|
||||||
|
thread_t* thread = child->threads;
|
||||||
|
|
||||||
|
// TODO free ctx
|
||||||
|
|
||||||
|
free(thread->regs);
|
||||||
|
free(thread->kernelstackbase);
|
||||||
|
free(thread);
|
||||||
free(child);
|
free(child);
|
||||||
|
|
||||||
retv.ret = child->pid;
|
retv.ret = child->pid;
|
||||||
|
|||||||
Reference in New Issue
Block a user