Merge branch '1679-handle-systems-with-broken-gettimeofday-system-calls' into 'v9_11'

Resolve "Handle systems with broken gettimeofday system calls"

See merge request isc-projects/bind9!3232
This commit is contained in:
Mark Andrews 2020-03-18 07:20:37 +00:00
commit 0fa64e6682

View file

@ -24,38 +24,6 @@
#include <isc/stdtime.h>
#include <isc/util.h>
#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) {
bool fixed = false;
if (tv->tv_usec < 0) {
fixed = 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 = 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;
@ -69,12 +37,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;
}