]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
752. [func] Correct bad tv_usec elements returned by gettimeofday().
authorMark Andrews <marka@isc.org>
Fri, 23 Feb 2001 23:12:28 +0000 (23:12 +0000)
committerMark Andrews <marka@isc.org>
Fri, 23 Feb 2001 23:12:28 +0000 (23:12 +0000)
CHANGES
lib/isc/include/isc/log.h
lib/isc/log.c
lib/isc/unix/time.c

diff --git a/CHANGES b/CHANGES
index 9a7c0e1cf162b6f1512de56ca6338002e14d6849..98a91693c86f9b054ce1581503e38a95f54f84f2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+ 752.  [func]          Correct bad tv_usec elements returned by gettimeofday().
+
  751.  [func]          Log successful zone loads / transfers.
 
  750.  [bug]           A query should not match a DNAME whose trust level
index f5054dcb10041a5d01422cba14ace1f5a9629bd7..11a4b515c1b52026ade95a8ad6db7b395466bdc6 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: log.h,v 1.36 2001/01/09 21:57:09 bwelling Exp $ */
+/* $Id: log.h,v 1.37 2001/02/23 23:12:27 marka Exp $ */
 
 #ifndef ISC_LOG_H
 #define ISC_LOG_H 1
@@ -138,6 +138,7 @@ extern isc_logmodule_t isc_modules[];
 #define ISC_LOGCATEGORY_GENERAL        (&isc_categories[1])
 
 #define ISC_LOGMODULE_SOCKET (&isc_modules[0])
+#define ISC_LOGMODULE_TIME (&isc_modules[1])
 
 ISC_LANG_BEGINDECLS
 
index 5b020a60ab5ff7a6de18719c9e65bc96b3687658..3666579ed6e4c96656e7ec4e17a36c604550f7be 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: log.c,v 1.56 2001/01/09 21:56:13 bwelling Exp $ */
+/* $Id: log.c,v 1.57 2001/02/23 23:12:25 marka Exp $ */
 
 /* Principal Authors: DCL */
 
@@ -192,6 +192,7 @@ isc_logcategory_t isc_categories[] = {
  */
 isc_logmodule_t isc_modules[] = {
        { "socket", 0 },
+       { "time", 0 },
        { NULL, 0 }
 };
 
index 9d9395d0d9e4cc50fc9607959edb439b7d5062e5..d2e7ffd6669fa22e8edbaae117e4453f9f17a2a8 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: time.c,v 1.30 2001/01/09 21:58:33 bwelling Exp $ */
+/* $Id: time.c,v 1.31 2001/02/23 23:12:28 marka Exp $ */
 
 #include <config.h>
 
@@ -25,6 +25,7 @@
 
 #include <sys/time.h>  /* Required for struct timeval on some platforms. */
 
+#include <isc/log.h>
 #include <isc/string.h>
 #include <isc/time.h>
 #include <isc/util.h>
  * need an initialized type.
  */
 
+#ifndef ISC_FIX_TV_USEC
+#define ISC_FIX_TV_USEC 1
+#endif
+
 /***
  *** Intervals
  ***/
@@ -130,9 +135,13 @@ isc_time_isepoch(isc_time_t *t) {
        return (ISC_FALSE);
 }
 
+
 isc_result_t
 isc_time_now(isc_time_t *t) {
        struct timeval tv;
+#if ISC_FIX_TV_USEC
+       isc_boolean_t fixed = ISC_FALSE;
+#endif
 
        /*
         * Set *t to the current absolute time.
@@ -152,8 +161,29 @@ isc_time_now(isc_time_t *t) {
         * happening are pretty much zero, but since the libisc library ensures
         * certain things to be true ...
         */
+#if ISC_FIX_TV_USEC
+       if (tv.tv_sec < 0) {
+               fixed = ISC_TRUE;
+               do {
+                       tv.tv_sec -= 1;
+                       tv.tv_usec += US_PER_S;
+               } while (tv.tv_usec < 0);
+       } else if (tv.tv_sec >= US_PER_S) {
+               fixed = ISC_TRUE;
+               do {
+                       tv.tv_sec += 1;
+                       tv.tv_usec -= US_PER_S;
+               } while (tv.tv_usec >=US_PER_S);
+       } else if (tv.tv_sec < 0)
+               return (ISC_R_UNEXPECTED);
+       if (fixed)
+               isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
+                             ISC_LOGMODULE_TIME, ISC_LOG_INFO,
+                             "gettimeofday returned bad tv_usec: corrected");
+#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.