itimerfix() fix for time validity check

Alexey Dokuchaev danfe at regency.nsu.ru
Mon Mar 31 09:45:29 PST 2003


Hello there,

While porting some apps written for Linux to FreeBSD, I've encountered
the fact that, while under Linux it's quite appropriate (and possible) to
pass million and more milliseconds as tv_usec value in

struct timeval {
	long tv_sec;
	long tv_usec;
};

used in functions like setitimer(), it's not like that in FreeBSD.

Brief investigation showed that itimerfix() treats tv_usec >= 1000000
invalid.  On contrary, Linux recalculates the values (and eventually,
tv_usec is indeed less than 1000000.

Since I'm unaware of what does any particular standard say on this
issue, but since the dominant number of apps are being written (and
designed) for Linux, this seems to cause run-time compatibility problem;
quite a few apps in out ports collection might need special patching.

As a probable solution to this problem, I'm posting a little patch that
fixes it, by recalculating and rebalancing values in tv structure, for
your further review.

./danfe
-------------- next part --------------
--- kern_time.c.orig	Tue Apr  1 00:25:02 2003
+++ kern_time.c	Tue Apr  1 00:26:42 2003
@@ -559,6 +559,9 @@
 itimerfix(struct timeval *tv)
 {
 
+	tv->tv_sec += tv->tv_usec / 1000000;
+	tv->tv_usec %= 1000000;
+
 	if (tv->tv_sec < 0 || tv->tv_sec > 100000000 ||
 	    tv->tv_usec < 0 || tv->tv_usec >= 1000000)
 		return (EINVAL);


More information about the freebsd-arch mailing list