From 13c1bcf2c1d5fbdca99cdddec726f822b68dddbc Mon Sep 17 00:00:00 2001 From: hrs Date: Mon, 5 Aug 2013 20:13:02 +0000 Subject: - Use time_uptime instead of time_second in data structures for PF_INET6 in kernel. This fixes various malfunction when the wall time clock is changed. Bump __FreeBSD_version to 1000041. - Use clock_gettime(CLOCK_MONOTONIC_FAST) in userland utilities. MFC after: 1 month --- usr.sbin/rtadvd/timer_subr.c | 49 +++++++------------------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) (limited to 'usr.sbin/rtadvd/timer_subr.c') diff --git a/usr.sbin/rtadvd/timer_subr.c b/usr.sbin/rtadvd/timer_subr.c index 2bebdd3..0ddf0a4 100644 --- a/usr.sbin/rtadvd/timer_subr.c +++ b/usr.sbin/rtadvd/timer_subr.c @@ -30,69 +30,34 @@ * SUCH DAMAGE. */ -#include #include #include #include #include #include +#include #include "timer.h" #include "timer_subr.h" -struct timeval * +struct timespec * rtadvd_timer_rest(struct rtadvd_timer *rat) { - static struct timeval returnval, now; + static struct timespec returnval, now; - gettimeofday(&now, NULL); - if (TIMEVAL_LEQ(&rat->rat_tm, &now)) { + clock_gettime(CLOCK_MONOTONIC_FAST, &now); + if (TS_CMP(&rat->rat_tm, &now, <=)) { syslog(LOG_DEBUG, "<%s> a timer must be expired, but not yet", __func__); - returnval.tv_sec = returnval.tv_usec = 0; + returnval.tv_sec = returnval.tv_nsec = 0; } else - TIMEVAL_SUB(&rat->rat_tm, &now, &returnval); + TS_SUB(&rat->rat_tm, &now, &returnval); return (&returnval); } -/* result = a + b */ -void -TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result) -{ - long l; - - if ((l = a->tv_usec + b->tv_usec) < MILLION) { - result->tv_usec = l; - result->tv_sec = a->tv_sec + b->tv_sec; - } - else { - result->tv_usec = l - MILLION; - result->tv_sec = a->tv_sec + b->tv_sec + 1; - } -} - -/* - * result = a - b - * XXX: this function assumes that a >= b. - */ -void -TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result) -{ - long l; - - if ((l = a->tv_usec - b->tv_usec) >= 0) { - result->tv_usec = l; - result->tv_sec = a->tv_sec - b->tv_sec; - } - else { - result->tv_usec = MILLION + l; - result->tv_sec = a->tv_sec - b->tv_sec - 1; - } -} - char * sec2str(uint32_t s, char *buf) { -- cgit v1.1