From: Roy Marples Date: Tue, 13 Nov 2012 20:40:04 +0000 (+0000) Subject: Normalise timing X-Git-Tag: v5.99.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4123fdf9107e7398bd85d1e11da088111f5e2483;p=thirdparty%2Fdhcpcd.git Normalise timing --- diff --git a/common.h b/common.h index f2a894ef..37b7a2c8 100644 --- a/common.h +++ b/common.h @@ -37,23 +37,27 @@ #define UNCONST(a) ((void *)(unsigned long)(const void *)(a)) #define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6) -#define tv_to_ms(ms, tv) \ - do { \ - ms = (tv)->tv_sec * 1000; \ - ms += (tv)->tv_usec / 1000; \ - } while (0 /* CONSTCOND */); -#define ms_to_tv(tv, ms) \ - do { \ - (tv)->tv_sec = ms / 1000; \ - (tv)->tv_usec = (ms - (tv)->tv_sec * 1000) * 1000; \ - } while (0 /* CONSTCOND */); -#define timernorm(tvp) \ - do { \ - while ((tvp)->tv_usec >= 1000000) { \ - (tvp)->tv_sec++; \ - (tvp)->tv_usec -= 1000000; \ - } \ - } while (0 /* CONSTCOND */); +#define timernorm(tv) do { \ + while ((tv)->tv_usec >= 1000000) { \ + (tv)->tv_sec++; \ + (tv)->tv_usec -= 1000000; \ + } \ +} while (0 /* CONSTCOND */); +#define tv_to_ms(ms, tv) do { \ + ms = (tv)->tv_sec * 1000; \ + ms += (tv)->tv_usec / 1000; \ +} while (0 /* CONSTCOND */); +#define ms_to_tv(tv, ms) do { \ + (tv)->tv_sec = ms / 1000; \ + (tv)->tv_usec = (ms - ((tv)->tv_sec * 1000)) * 1000; \ +} while (0 /* CONSTCOND */); + +#ifndef TIMEVAL_TO_TIMESPEC +#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} while (0 /* CONSTCOND */) +#endif #if __GNUC__ > 2 || defined(__INTEL_COMPILER) # define _noreturn __attribute__((__noreturn__)) diff --git a/dhcpcd.c b/dhcpcd.c index c219a564..23849193 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -330,6 +330,7 @@ send_message(struct interface *iface, int type, } tv.tv_sec = state->interval + DHCP_RAND_MIN; tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U); + timernorm(&tv); syslog(LOG_DEBUG, "%s: sending %s (xid 0x%x), next in %0.2f seconds", iface->name, get_dhcp_op(type), state->xid, diff --git a/eloop.c b/eloop.c index 85219780..9a28890f 100644 --- a/eloop.c +++ b/eloop.c @@ -309,8 +309,7 @@ eloop_start(const sigset_t *cursigs) continue; } timersub(&timeouts->when, &now, &tv); - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_usec * 1000; + TIMEVAL_TO_TIMESPEC(&tv, &ts); tsp = &ts; } else /* No timeouts, so wait forever */