Module Name:    src
Committed By:   martin
Date:           Sun Oct 13 15:33:17 UTC 2024

Modified Files:
        src/share/man/man9 [netbsd-9]: ts2timo.9
        src/sys/kern [netbsd-9]: subr_time.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #1909):

        share/man/man9/ts2timo.9: revision 1.4
        share/man/man9/ts2timo.9: revision 1.5
        sys/kern/subr_time.c: revision 1.39 (patch)

ts2timo() uses struct timespec, those don't have a tv_usec
field, they have tv_nsec instead.   EINVAL will happen if the
tv_nsec field is invalid, not the non-existant tv_usec field.
PR kern/58733 - avoid ts2timo() clobbering its arg

See the PR for the gory details - in the TIMER_ABSTIME case
ts2timo() should not (really *must* not) alter the timespec
it is passed (in that case it should be const - but for now
anyway, cannot be for the TIMER_RELTIME case, and there is
just one of them!).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.34.1 src/share/man/man9/ts2timo.9
cvs rdiff -u -r1.20.8.1 -r1.20.8.2 src/sys/kern/subr_time.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man9/ts2timo.9
diff -u src/share/man/man9/ts2timo.9:1.3 src/share/man/man9/ts2timo.9:1.3.34.1
--- src/share/man/man9/ts2timo.9:1.3	Fri May 24 14:41:32 2013
+++ src/share/man/man9/ts2timo.9	Sun Oct 13 15:33:17 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ts2timo.9,v 1.3 2013/05/24 14:41:32 njoly Exp $
+.\"	$NetBSD: ts2timo.9,v 1.3.34.1 2024/10/13 15:33:17 martin Exp $
 .\"
 .\" Copyright (c) 2013 Christos Zoulas
 .\" All rights reserved.
@@ -51,7 +51,7 @@ or
 .Dv TIMER_RELTIME .
 If the interval is specified as an absolute time, then the
 .Fa clock_id
-clock is used to convert it to a relative time.
+clock is used to calculate the corresponding relative time.
 If the
 .Fa start
 argument is not
@@ -63,18 +63,23 @@ clock is placed in that argument.
 On success
 .Fn ts2timo
 returns
-.Dv 0 .
+.Dv 0 ,
+and places the computed number of ticks
+in the integer referenced by
+.Fa timo .
 On failure it returns
 .Er ETIMEDOUT
 if  interval computed was
 .Dv 0
-or negative, and
+or negative, or
 .Er EINVAL
-if
-.Fa ts->tv_usec
-field in the computed interval is out of range, or the
+if the
+.Fa ts->tv_nsec
+field is out of range, or the
 .Fa clock_id
-argument is invalid.
+argument is invalid, or if
+computing the relative time from a supplied absolute value
+would cause an arithmetic overflow.
 .Sh SEE ALSO
 .Xr clock_gettime 2 ,
 .Xr clock_nanosleep 2

Index: src/sys/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.20.8.1 src/sys/kern/subr_time.c:1.20.8.2
--- src/sys/kern/subr_time.c:1.20.8.1	Fri Oct 11 17:18:05 2024
+++ src/sys/kern/subr_time.c	Sun Oct 13 15:33:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.20.8.1 2024/10/11 17:18:05 martin Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.20.8.2 2024/10/13 15:33:17 martin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.20.8.1 2024/10/11 17:18:05 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.20.8.2 2024/10/13 15:33:17 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -316,8 +316,10 @@ ts2timo(clockid_t clock_id, int flags, s
 		if ((error = clock_gettime1(clock_id, start)) != 0)
 			return error;
 
-	if (flags)
-		timespecsub(ts, start, ts);
+	if (flags) {
+		timespecsub(ts, start, &tsd);
+		ts = &tsd;
+	}
 
 	if ((error = itimespecfix(ts)) != 0)
 		return error;

Reply via email to