diff --git a/src/arp.c b/src/arp.c index 6d1dc1b..6d9b35e 100644 --- a/src/arp.c +++ b/src/arp.c @@ -491,22 +491,13 @@ int arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts) __attribute__((noreturn)) static void quit_after_lease_handler(struct client_state_t cs[static 1]) { - struct timespec res; - if (clock_gettime(CLOCK_MONOTONIC, &res) < 0) { - suicide("%s: (%s) clock_gettime failed: %s", - client_config.interface, __func__, strerror(errno)); - } - time_t init_ts = res.tv_sec; + long long init_ts = curms(); for (;;) { if (arp_announcement(cs) >= 0) exit(EXIT_SUCCESS); log_warning("%s: (%s) Failed to send ARP announcement: %s", client_config.interface, __func__, strerror(errno)); - if (clock_gettime(CLOCK_MONOTONIC, &res) < 0) { - suicide("%s: (%s) clock_gettime failed: %s", - client_config.interface, __func__, strerror(errno)); - } - if (res.tv_sec - init_ts > 60) break; + if (curms() - init_ts > (60LL * 1000LL)) break; } exit(EXIT_FAILURE); } diff --git a/src/sys.c b/src/sys.c index b7350c4..2cee10e 100644 --- a/src/sys.c +++ b/src/sys.c @@ -38,6 +38,16 @@ #include "ndhc.h" #include "sys.h" +long long IMPL_curms(const char *parent_function) +{ + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { + suicide("%s: (%s) clock_gettime failed: %s", + client_config.interface, parent_function, strerror(errno)); + } + return ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL; +} + void epoll_add(int epfd, int fd) { struct epoll_event ev; diff --git a/src/sys.h b/src/sys.h index 25e572f..e1275cc 100644 --- a/src/sys.h +++ b/src/sys.h @@ -31,18 +31,13 @@ #include #include "ndhc-defines.h" -static inline long long curms() -{ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL; -} - static inline size_t min_size_t(size_t a, size_t b) { return a < b ? a : b; } +#define curms() IMPL_curms(__func__) +long long IMPL_curms(const char *parent_function); void epoll_add(int epfd, int fd); void epoll_del(int epfd, int fd);