Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jan 2000 22:39:50 +0000
From:      Ben Smithurst <ben@scientia.demon.co.uk>
To:        Scott Blachowicz <Scott.Blachowicz@seaslug.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Odd gettimeofday() return values
Message-ID:  <20000120223950.A24986@strontium.scientia.demon.co.uk>
In-Reply-To: <uaem1v3l5.fsf@seaslug.org>
References:  <uaem1v3l5.fsf@seaslug.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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




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