1078. [bug] We failed to correct bad tv_usec values in one case.

[RT #1966]
This commit is contained in:
Mark Andrews
2001-10-30 02:39:33 +00:00
parent fde3820de9
commit bc508906db
2 changed files with 43 additions and 2 deletions

View File

@@ -1,3 +1,6 @@
1078. [bug] We failed to correct bad tv_usec values in one case.
[RT #1966]
1077. [func] Do not accept further recursive clients when
the total number of of recursive lookups being
processed exceeds max-recursive-clients, even

View File

@@ -15,17 +15,50 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: stdtime.c,v 1.11 2001/02/13 13:24:09 marka Exp $ */
/* $Id: stdtime.c,v 1.12 2001/10/30 02:39:33 marka Exp $ */
#include <config.h>
#include <stdlib.h> /* NULL */
#include <syslog.h>
#include <sys/time.h>
#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) {
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)
syslog(LOG_ERR, "gettimeofday returned bad tv_usec: corrected");
}
#endif
void
isc_stdtime_get(isc_stdtime_t *t) {
struct timeval tv;
@@ -39,7 +72,12 @@ isc_stdtime_get(isc_stdtime_t *t) {
RUNTIME_CHECK(gettimeofday(&tv, NULL) != -1);
INSIST(tv.tv_usec >= 0 && tv.tv_usec < 1000000);
#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;
}