Skip to content

Commit

Permalink
nanosleep: don't overwrite error with copyout success status
Browse files Browse the repository at this point in the history
When nanosleep gets interrupted, it returns EINTR.  In the case of a
non-zero error status, sys_nanosleep will copyout() the remaining sleep
time.  However it would overwrite the nanosleep error status with the
error status of copyout() -- which is 0 (success) most of the time.  This
means the important error status of nanosleep (EINTR) would be overwritten
by 0.  Follow FreeBSD and NetBSD and only return the copyout status if it
failed.

Reported-by: walt
  • Loading branch information
corecode committed May 3, 2009
1 parent 54eeac0 commit 55d25c8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sys/kern/kern_time.c
Expand Up @@ -351,8 +351,13 @@ sys_nanosleep(struct nanosleep_args *uap)
/*
* copyout the residual if nanosleep was interrupted.
*/
if (error && uap->rmtp)
error = copyout(&rmt, uap->rmtp, sizeof(rmt));
if (error && uap->rmtp) {
int error2;

error2 = copyout(&rmt, uap->rmtp, sizeof(rmt));
if (error2)
error = error2;
}
return (error);
}

Expand Down

0 comments on commit 55d25c8

Please sign in to comment.