Handle possible clock_gettime() errors in curms().

Use curms() instead of new clock_gettime() call points, too.
This commit is contained in:
Nicholas J. Kain 2017-02-24 08:51:36 -05:00
parent a39f1dabfe
commit 2a26acacdd
3 changed files with 14 additions and 18 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -31,18 +31,13 @@
#include <time.h>
#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);