Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Remaining time for clock_nanosleep(2) & TIMER_ABSTIME



Hi,

Accodring to the Open Group online specification[1] for
clock_nanosleep(2); if TIMER_ABSTIME is set, the timespec struct to
report the remaining time should not be altered. But our
implementation do not obey, setting all struct members to 0.

Here are 2 patches for review :

1) netbsd-clocknanosleepabstime.diff
   That fix the issue to only copyout the structure if TIMER_ABSTIME
   is not set

2) netbsd-clocknanosleeptestcase.diff
   The corresponding testcase that exercize it.

Thanks.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
Index: sys/kern/kern_time.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_time.c,v
retrieving revision 1.188
diff -u -p -r1.188 kern_time.c
--- sys/kern/kern_time.c	7 Jul 2016 06:55:43 -0000	1.188
+++ sys/kern/kern_time.c	11 Nov 2016 13:14:01 -0000
@@ -319,7 +319,8 @@ sys_clock_nanosleep(struct lwp *l, const
 	if (SCARG(uap, rmtp) == NULL || (error != 0 && error != EINTR))
 		goto out;
 
-	if ((error1 = copyout(&rmt, SCARG(uap, rmtp), sizeof(rmt))) != 0)
+	if ((SCARG(uap, flags) & TIMER_ABSTIME) == 0 &&
+	    (error1 = copyout(&rmt, SCARG(uap, rmtp), sizeof(rmt))) != 0)
 		error = error1;
 out:
 	*retval = error;
Index: tests/lib/libc/sys/t_clock_nanosleep.c
===================================================================
RCS file: tests/lib/libc/sys/t_clock_nanosleep.c
diff -N tests/lib/libc/sys/t_clock_nanosleep.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/lib/libc/sys/t_clock_nanosleep.c	11 Nov 2016 13:15:57 -0000
@@ -0,0 +1,63 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD$");
+
+#include <atf-c.h>
+#include <time.h>
+
+ATF_TC(clock_nanosleep_remain);
+ATF_TC_HEAD(clock_nanosleep_remain, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	    "Check clock_nanosleep(2) remaining time");
+}
+
+ATF_TC_BODY(clock_nanosleep_remain, tc)
+{
+	struct timespec rqtp, rmtp;
+
+	rqtp.tv_sec = 0; rqtp.tv_nsec = 0;
+	rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
+	ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, 0, &rqtp, &rmtp) == 0);
+	ATF_CHECK(rmtp.tv_sec == 0 && rmtp.tv_nsec == 0);
+
+	ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &rqtp) == 0);
+	rmtp.tv_sec = -1; rmtp.tv_nsec = -1;
+	ATF_REQUIRE(clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &rqtp, &rmtp) == 0);
+	ATF_CHECK(rmtp.tv_sec == -1 && rmtp.tv_nsec == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, clock_nanosleep_remain);
+
+	return atf_no_error();
+}
Index: tests/lib/libc/sys/Makefile
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/sys/Makefile,v
retrieving revision 1.44
diff -u -p -r1.44 Makefile
--- tests/lib/libc/sys/Makefile	6 Nov 2016 15:04:14 -0000	1.44
+++ tests/lib/libc/sys/Makefile	11 Nov 2016 13:15:57 -0000
@@ -12,6 +12,7 @@ TESTS_C+=		t_access
 TESTS_C+=		t_bind
 TESTS_C+=		t_chroot
 TESTS_C+=		t_clock_gettime
+TESTS_C+=		t_clock_nanosleep
 TESTS_C+=		t_clone
 TESTS_C+=		t_connect
 TESTS_C+=		t_dup
Index: distrib/sets/lists/tests/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/tests/mi,v
retrieving revision 1.698
diff -u -p -r1.698 mi
--- distrib/sets/lists/tests/mi	11 Nov 2016 07:39:58 -0000	1.698
+++ distrib/sets/lists/tests/mi	11 Nov 2016 13:15:58 -0000
@@ -2685,6 +2685,7 @@
 ./usr/tests/lib/libc/sys/t_cerror		tests-obsolete		obsolete
 ./usr/tests/lib/libc/sys/t_chroot		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/sys/t_clock_gettime	tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libc/sys/t_clock_nanosleep	tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/sys/t_clone		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/sys/t_connect		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libc/sys/t_context		tests-obsolete		obsolete
Index: distrib/sets/lists/debug/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/debug/mi,v
retrieving revision 1.175
diff -u -p -r1.175 mi
--- distrib/sets/lists/debug/mi	11 Nov 2016 07:39:58 -0000	1.175
+++ distrib/sets/lists/debug/mi	11 Nov 2016 13:15:59 -0000
@@ -2014,6 +2014,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_cerror.debug		tests-obsolete		obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_chroot.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_clock_gettime.debug	tests-lib-debug		debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_clock_nanosleep.debug	tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_clone.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_connect.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libc/sys/t_context.debug		tests-obsolete		obsolete,compattestfile


Home | Main Index | Thread Index | Old Index