* 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
#define ISC_LOGCATEGORY_GENERAL (&isc_categories[1])
#define ISC_LOGMODULE_SOCKET (&isc_modules[0])
+#define ISC_LOGMODULE_TIME (&isc_modules[1])
ISC_LANG_BEGINDECLS
* 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 */
*/
isc_logmodule_t isc_modules[] = {
{ "socket", 0 },
+ { "time", 0 },
{ NULL, 0 }
};
* 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>
#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
***/
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.
* 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.