From aca6aeff4d9c85779b080fd00d78d1fc22795a2d Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Thu, 13 Feb 2020 08:19:13 +0000 Subject: trust gettimeofday doing the right thing --- usr.bin/dig/lib/isc/unix/stdtime.c | 41 +------------------------------ usr.bin/dig/lib/isc/unix/time.c | 49 +------------------------------------- 2 files changed, 2 insertions(+), 88 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/dig/lib/isc/unix/stdtime.c b/usr.bin/dig/lib/isc/unix/stdtime.c index b2a172f87a6..2f9d94c50f6 100644 --- a/usr.bin/dig/lib/isc/unix/stdtime.c +++ b/usr.bin/dig/lib/isc/unix/stdtime.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: stdtime.c,v 1.2 2020/02/11 23:26:12 jsg Exp $ */ +/* $Id: stdtime.c,v 1.3 2020/02/13 08:19:12 florian Exp $ */ /*! \file */ @@ -28,38 +28,6 @@ #include #include -#ifndef ISC_FIX_TV_USEC -#define ISC_FIX_TV_USEC 1 -#endif - -#define US_PER_S 1000000 - -#if ISC_FIX_TV_USEC -static inline void -fix_tv_usec(struct timeval *tv) { - isc_boolean_t fixed = ISC_FALSE; - - if (tv->tv_usec < 0) { - fixed = ISC_TRUE; - do { - tv->tv_sec -= 1; - tv->tv_usec += US_PER_S; - } while (tv->tv_usec < 0); - } else if (tv->tv_usec >= US_PER_S) { - fixed = ISC_TRUE; - do { - tv->tv_sec += 1; - tv->tv_usec -= US_PER_S; - } while (tv->tv_usec >=US_PER_S); - } - /* - * Call syslog directly as we are called from the logging functions. - */ - if (fixed) - (void)syslog(LOG_ERR, "gettimeofday returned bad tv_usec: corrected"); -} -#endif - void isc_stdtime_get(isc_stdtime_t *t) { struct timeval tv; @@ -73,12 +41,5 @@ isc_stdtime_get(isc_stdtime_t *t) { RUNTIME_CHECK(gettimeofday(&tv, NULL) != -1); -#if ISC_FIX_TV_USEC - fix_tv_usec(&tv); - INSIST(tv.tv_usec >= 0); -#else - INSIST(tv.tv_usec >= 0 && tv.tv_usec < US_PER_S); -#endif - *t = (unsigned int)tv.tv_sec; } diff --git a/usr.bin/dig/lib/isc/unix/time.c b/usr.bin/dig/lib/isc/unix/time.c index f0f65a9b54c..6de63f3820d 100644 --- a/usr.bin/dig/lib/isc/unix/time.c +++ b/usr.bin/dig/lib/isc/unix/time.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: time.c,v 1.3 2020/02/12 13:05:04 jsg Exp $ */ +/* $Id: time.c,v 1.4 2020/02/13 08:19:12 florian Exp $ */ /*! \file */ @@ -38,7 +38,6 @@ #define NS_PER_S 1000000000 /*%< Nanoseconds per second. */ #define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */ -#define US_PER_S 1000000 /*%< Microseconds per second. */ /* * All of the INSIST()s checks of nanoseconds < NS_PER_S are for @@ -47,10 +46,6 @@ * need an initialized type. */ -#ifndef ISC_FIX_TV_USEC -#define ISC_FIX_TV_USEC 1 -#endif - /*% *** Intervals ***/ @@ -58,32 +53,6 @@ static const interval_t zero_interval = { 0, 0 }; const interval_t * const interval_zero = &zero_interval; -#if ISC_FIX_TV_USEC -static inline void -fix_tv_usec(struct timeval *tv) { - isc_boolean_t fixed = ISC_FALSE; - - if (tv->tv_usec < 0) { - fixed = ISC_TRUE; - do { - tv->tv_sec -= 1; - tv->tv_usec += US_PER_S; - } while (tv->tv_usec < 0); - } else if (tv->tv_usec >= US_PER_S) { - fixed = ISC_TRUE; - do { - tv->tv_sec += 1; - tv->tv_usec -= US_PER_S; - } while (tv->tv_usec >=US_PER_S); - } - /* - * Call syslog directly as was are called from the logging functions. - */ - if (fixed) - (void)syslog(LOG_ERR, "gettimeofday returned bad tv_usec: corrected"); -} -#endif - void interval_set(interval_t *i, unsigned int seconds, unsigned int nanoseconds) @@ -156,22 +125,6 @@ isc_time_now(isc_time_t *t) { return (ISC_R_UNEXPECTED); } - /* - * Does POSIX guarantee the signedness of tv_sec and tv_usec? If not, - * then this test will generate warnings for platforms on which it is - * unsigned. In any event, the chances of any of these problems - * happening are pretty much zero, but since the libisc library ensures - * certain things to be true ... - */ -#if ISC_FIX_TV_USEC - fix_tv_usec(&tv); - if (tv.tv_sec < 0) - return (ISC_R_UNEXPECTED); -#else - if (tv.tv_sec < 0 || tv.tv_usec < 0 || tv.tv_usec >= US_PER_S) - return (ISC_R_UNEXPECTED); -#endif - /* * Ensure the tv_sec value fits in t->seconds. */ -- cgit v1.2.3