From owner-freebsd-arch@FreeBSD.ORG Mon Mar 31 09:45:28 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7065E37B401 for ; Mon, 31 Mar 2003 09:45:28 -0800 (PST) Received: from mail.nsu.ru (mx.nsu.ru [193.124.215.71]) by mx1.FreeBSD.org (Postfix) with ESMTP id C9ADC43FCB for ; Mon, 31 Mar 2003 09:45:25 -0800 (PST) (envelope-from danfe@regency.nsu.ru) Received: from drweb by mail.nsu.ru with drweb-scanned (Exim 3.20 #1) id 1903LE-0003uE-00 for arch@freebsd.org; Tue, 01 Apr 2003 00:45:04 +0700 Received: from regency.nsu.ru ([193.124.210.26]) by mail.nsu.ru with esmtp (Exim 3.20 #1) id 1903LC-0003rE-00 for arch@freebsd.org; Tue, 01 Apr 2003 00:45:02 +0700 Received: from regency.nsu.ru (localhost [127.0.0.1]) by regency.nsu.ru (8.12.8/8.12.8) with ESMTP id h2VHit1Q051731 for ; Tue, 1 Apr 2003 00:44:55 +0700 (NOVST) (envelope-from danfe@regency.nsu.ru) Received: (from danfe@localhost) by regency.nsu.ru (8.12.8/8.12.8/Submit) id h2VHitJW051730 for arch@freebsd.org; Tue, 1 Apr 2003 00:44:55 +0700 (NOVST) Date: Tue, 1 Apr 2003 00:44:54 +0700 From: Alexey Dokuchaev To: arch@freebsd.org Message-ID: <20030331174454.GA51622@regency.nsu.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6c2NcOVqGQ03X4Wi" Content-Disposition: inline User-Agent: Mutt/1.4i X-Envelope-To: arch@freebsd.org Subject: itimerfix() fix for time validity check X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Mar 2003 17:45:29 -0000 --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--