From owner-freebsd-questions Thu Jan 20 16: 7: 4 2000 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id CFD0C15385 for ; Thu, 20 Jan 2000 16:06:54 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.12 #1) id 12BQF4-00048T-00; Thu, 20 Jan 2000 22:39:50 +0000 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #1) id 12BQF4-0006YF-00; Thu, 20 Jan 2000 22:39:50 +0000 Date: Thu, 20 Jan 2000 22:39:50 +0000 From: Ben Smithurst To: Scott Blachowicz Cc: freebsd-questions@freebsd.org Subject: Re: Odd gettimeofday() return values Message-ID: <20000120223950.A24986@strontium.scientia.demon.co.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Scott Blachowicz wrote: > $1 = {tv_sec = 948333207, tv_usec = -694210779} > > I'm not sure when this really started happening - I think it's been going > on for a while now (the earliest I see in my log files is mid-November, so > I guess it's not a Y2K bug :-)). At any rate, shouldn't that tv_usec > field be in the range of 0..999999? If not, how should I hack the source > here to interpret the above return value? Borrow enough seconds off of > tv_sec until tv_usec is positive? Clamp tv_usec to zero? Or do something > equivalent to this: > > if (tv_usec < 0 || tv_usec > 1000000) { > now.tv_sec = time(NULL); this is just as unreliable, since time() just calls gettimeofday(). > now.tv_usec = 0; > } > > ??? Any ideas/suggestions? > > Also...I don't know if it's related or not, but I've gotten some of those > > Jan 19 06:28:55 sabmail /kernel: calcru: negative time of -695391396 usec for pid 85131 (awk) I'd guess they're related, the numbers are quite close (relatively at least). All I can suggest really is upgrade to the latest -STABLE, unless someone has a better idea. I recall talk of this calcru problem being fixed (I used to see it a bit, too, though I never noticed the gettimeofday problem). For a temporary hack (*only* if upgrading is too much trouble) I'd probably set tv_usec to zero and leave tv_sec alone (probably writing some log message so you can tell if that's a possible cause of something else breaking). Alternatively, write a loop to try gettimeofday up to (say) five times until you get a valid result. Both of these hacks seem unspeakably ugly though, upgrading doesn't. :-) -- Ben Smithurst | PGP: 0x99392F7D ben@scientia.demon.co.uk | key available from keyservers and | ben+pgp@scientia.demon.co.uk To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message