Skip to content

Commit

Permalink
Handle possible clock_gettime() errors in curms().
Browse files Browse the repository at this point in the history
Use curms() instead of new clock_gettime() call points, too.
  • Loading branch information
niklata committed Feb 24, 2017
1 parent a39f1da commit 2a26aca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
13 changes: 2 additions & 11 deletions src/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions src/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2a26aca

Please sign in to comment.