Date: 19 Jan 2000 19:12:22 -0800 From: Scott Blachowicz <Scott.Blachowicz@seaslug.org> To: freebsd-questions@freebsd.org Subject: Odd gettimeofday() return values Message-ID: <uaem1v3l5.fsf@seaslug.org>
next in thread | raw e-mail | index | archive | help
The following message is a courtesy copy of an article that has been posted to comp.unix.bsd.freebsd.misc as well. Hi- I'm running the named from bind-8.2.2P5 (and a couple earlier versions) on my home system running FreeBSD-3.2. I've been getting some assertions out of my named that cause it to generate a core file and exit. It turns out that it is doing some range checking on the time values it gets and the root cause of the problem seems to be that gettimeofday() is sometimes returning screwy values in the tv_usec field of the 'struct tm' it returns. # gdb /usr/local/sbin/named.unstripped named-20000119-2.core ...etc... (gdb) where #0 0x28115c78 in kill () from /usr/lib/libc.so.3 #1 0x28149e34 in abort () from /usr/lib/libc.so.3 #2 0x8070555 in ns_panic (category=18, dump_core=1, format=0x80ba630 "%s:%d: %s(%s)%s%s failed.") at ns_glue.c:167 #3 0x80705bc in ns_assertion_failed (file=0x80bf8f0 "ev_timers.c", line=114, type=assert_insist, cond=0x80bf8c6 "now.tv_usec >= 0 && now.tv_usec < 1000000", print_errno=0) at ns_glue.c:176 #4 0x8088b4d in __evNowTime () at ev_timers.c:114 #5 0x80871c5 in __evGetNext (opaqueCtx={opaque = 0x8127000}, opaqueEv=0xbfbfd6c0, options=2) at eventlib.c:201 #6 0x805eacc in main (argc=3, argv=0xbfbfd7fc, envp=0xbfbfd800) at ns_main.c:534 #7 0x804b23d in _start () (gdb) up 4 #4 0x8088b4d in __evNowTime () at ev_timers.c:114 114 INSIST(now.tv_usec >= 0 && now.tv_usec < 1000000); (gdb) list 109 evNowTime() { 110 struct timeval now; 111 112 if (gettimeofday(&now, NULL) < 0) 113 return (evConsTime(0, 0)); 114 INSIST(now.tv_usec >= 0 && now.tv_usec < 1000000); 115 return (evTimeSpec(now)); 116 } 117 118 struct timespec (gdb) p now $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); 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) messages in my /var/log/messages, but it looks suspiciously close to the same idea...maybe I should try the remedy mentioned in the FAQ under troubleshooting (i.e. run 'sysctl -w kern.timecounter.method=1')? Any other ideas? -- Scott.Blachowicz@seaslug.org 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?uaem1v3l5.fsf>