From 55d25c8782a76b25372313a908dff0a66d6ff342 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Sun, 3 May 2009 23:06:53 +0200 Subject: [PATCH] nanosleep: don't overwrite error with copyout success status 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 --- sys/kern/kern_time.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 0432052eaf..ccd6633317 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -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); } -- 2.11.4.GIT