|
@@ -20,7 +20,7 @@ void sys__exit(int exitcode)
|
|
|
{
|
|
|
struct addrspace * as;
|
|
|
struct proc * p = curproc;
|
|
|
- p->exitcode = exitcode;
|
|
|
+ p->exitcode = _MKWAIT_EXIT(exitcode);
|
|
|
DEBUG(DB_SYSCALL,"Syscall: _exit(%d)\n",exitcode);
|
|
|
KASSERT(curproc->p_addrspace != NULL);
|
|
|
|
|
@@ -82,8 +82,7 @@ int sys_getpid(pid_t * retval)
|
|
|
|
|
|
int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
|
|
|
{
|
|
|
- (void)status;
|
|
|
- if (options != 0)
|
|
|
+ if (options != 0 || !(void *)(status))
|
|
|
{
|
|
|
return(EINVAL);
|
|
|
}
|
|
@@ -92,16 +91,19 @@ int sys_waitpid(pid_t pid, userptr_t status, int options, pid_t * retval)
|
|
|
struct proc * target = getChild(curproc, pid);
|
|
|
|
|
|
if (!(target)) return ECHILD;
|
|
|
- if (target->exitcode >= 0)
|
|
|
+ if (!(target->exitcode >= 0))
|
|
|
{
|
|
|
- *retval = target->exitcode;
|
|
|
- return 0;
|
|
|
+ lock_acquire(target->waitlock);
|
|
|
+ cv_wait(target->waiting, target->waitlock);
|
|
|
+ lock_release(target->waitlock);
|
|
|
}
|
|
|
-
|
|
|
- lock_acquire(target->waitlock);
|
|
|
- cv_wait(target->waiting, target->waitlock);
|
|
|
- lock_release(target->waitlock);
|
|
|
+ int exitstatus = target->exitcode;
|
|
|
*retval = target->exitcode;
|
|
|
+ int result = copyout((void *)&exitstatus, status, sizeof(int));
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
proc_destroy(target);
|
|
|
return 0;
|
|
|
}
|