Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Apr 2003 00:44:54 +0700
From:      Alexey Dokuchaev <danfe@regency.nsu.ru>
To:        arch@freebsd.org
Subject:   itimerfix() fix for time validity check
Message-ID:  <20030331174454.GA51622@regency.nsu.ru>

next in thread | raw e-mail | index | archive | help

--6c2NcOVqGQ03X4Wi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

--6c2NcOVqGQ03X4Wi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kern_time.c.diff"

--- 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);

--6c2NcOVqGQ03X4Wi--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030331174454.GA51622>