* SUCH DAMAGE.
*/
-#ifdef __APPLE__
-# include <mach/mach_time.h>
-# include <mach/kern_return.h>
-#endif
-
#include <sys/param.h>
#include <sys/time.h>
return buf;
}
-/* Handy function to get the time.
- * We only care about time advancements, not the actual time itself
- * Which is why we use CLOCK_MONOTONIC, but it is not available on all
- * platforms.
- */
-#define NO_MONOTONIC "host does not support a monotonic clock - timing can skew"
-int
-get_monotonic(struct timespec *ts)
-{
-
-#if defined(_POSIX_MONOTONIC_CLOCK) && defined(CLOCK_MONOTONIC)
- return clock_gettime(CLOCK_MONOTONIC, ts);
-#elif defined(__APPLE__)
- /* We can use mach kernel functions here.
- * This is crap though - why can't they implement clock_gettime?*/
- static struct mach_timebase_info info = { 0, 0 };
- static double factor = 0.0;
- uint64_t nano;
- long rem;
-
- if (!posix_clock_set) {
- if (mach_timebase_info(&info) == KERN_SUCCESS) {
- factor = (double)info.numer / (double)info.denom;
- clock_monotonic = posix_clock_set = 1;
- }
- }
- if (clock_monotonic) {
- nano = mach_absolute_time();
- if ((info.denom != 1 || info.numer != 1) && factor != 0.0)
- nano *= factor;
- ts->tv_sec = nano / NSEC_PER_SEC;
- ts->tv_nsec = nano % NSEC_PER_SEC;
- if (ts->tv_nsec < 0) {
- ts->tv_sec--;
- ts->tv_nsec += NSEC_PER_SEC;
- }
- return 0;
- }
-#endif
-
-#if 0
- /* Something above failed, so fall back to gettimeofday */
- if (!posix_clock_set) {
- logger(NULL, LOG_WARNING, NO_MONOTONIC);
- posix_clock_set = 1;
- }
-#endif
- {
- struct timeval tv;
- if (gettimeofday(&tv, NULL) == 0) {
- TIMEVAL_TO_TIMESPEC(&tv, ts);
- return 0;
- }
- }
-
- return -1;
-}
-
#if USE_LOGFILE
void
logger_open(struct dhcpcd_ctx *ctx)
{
struct timespec tv;
- if (get_monotonic(&tv) == -1)
+ if (clock_gettime(CLOCK_MONOTONIC, &tv) == -1)
return -1;
return tv.tv_sec;
}
state->renew = state->rebind = state->expire = 0;
state->lowpl = ND6_INFINITE_LIFETIME;
if (!acquired) {
- get_monotonic(&aq);
+ clock_gettime(CLOCK_MONOTONIC, &aq);
acquired = &aq;
}
nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
if ((now = time(NULL)) == -1)
goto ex;
- get_monotonic(&acquired);
+ clock_gettime(CLOCK_MONOTONIC, &acquired);
acquired.tv_sec -= now - st.st_mtime;
/* Check to see if the lease is still valid */
struct timespec now, w;
struct eloop_timeout *t, *tt = NULL;
- get_monotonic(&now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
timespecadd(&now, when, &w);
/* Check for time_t overflow. */
if (timespeccmp(&w, &now, <)) {
struct timespec now;
/* Check we have a working monotonic clock. */
- if (get_monotonic(&now) == -1)
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
return NULL;
ctx = calloc(1, sizeof(*ctx));
(uint32_t)(lifetime->ia6t_expire -
MIN(t, lifetime->ia6t_expire));
/* Calculate the created time */
- get_monotonic(&ia->created);
+ clock_gettime(CLOCK_MONOTONIC, &ia->created);
ia->created.tv_sec -=
lifetime->ia6t_vltime - ia->prefix_vltime;
} else
struct timespec n;
if (now == NULL) {
- get_monotonic(&n);
+ clock_gettime(CLOCK_MONOTONIC, &n);
now = &n;
}
timespecsub(now, &ap->acquired, &n);
if (ap->flags & IPV6_AF_NEW)
i++;
if (!timespecisset(&now))
- get_monotonic(&now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
ipv6_addaddr(ap, &now);
}
}
DHCPCD_EXITING) && apf)
{
if (!timespecisset(&now))
- get_monotonic(&now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
ipv6_addaddr(apf, &now);
}
if (drop == 2)
ia->iface->name);
return;
}
- get_monotonic(&tv);
+ clock_gettime(CLOCK_MONOTONIC, &tv);
if ((ia1 = ipv6_createtempaddr(ia, &tv)) == NULL)
logger(ia->iface->ctx, LOG_ERR,
"ipv6_createtempaddr: %m");
logger(ia->iface->ctx, LOG_DEBUG, "%s: regen temp addr %s",
ia->iface->name, ia->saddr);
- get_monotonic(&tv);
+ clock_gettime(CLOCK_MONOTONIC, &tv);
ia1 = ipv6_createtempaddr(ia, &tv);
if (ia1)
ipv6_addaddr(ia1, &tv);
if (ifp->ctx->ipv6 == NULL)
return;
- get_monotonic(&now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
if (rap->iface == ifp) {
rap->data_len = len;
}
- get_monotonic(&rap->received);
+ clock_gettime(CLOCK_MONOTONIC, &rap->received);
rap->flags = nd_ra->nd_ra_flags_reserved;
if (new_rap == 0 && rap->lifetime == 0)
logger(ifp->ctx, LOG_WARNING, "%s: %s router available",
uint8_t expired, valid, validone;
ifp = arg;
- get_monotonic(&now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
expired = 0;
timespecclear(&next);