Commit 6c4cd12f authored by Scott Vokes's avatar Scott Vokes
Browse files

Note gettimeofday(2) for second handling should use clock_gettime(2).

gettimeofday(2) is vulnerable to issues around time changes (DST, leap
seconds, other clock resets) that could cause strange behavior.
clock_gettime with CLOCK_MONOTONIC will give more accurate time deltas,
and should be used instead. (clock_gettime is not available on OSX,
and possibly other OSs, so it should be wrapped.)
parent e7f39d36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ static void tick_handler(example_state *s) {

static time_t get_cur_second(void) {
    struct timeval tv;
    gettimeofday(&tv, 0);
    gettimeofday(&tv, 0);  // TODO: clock_gettime
    return tv.tv_sec;
}

+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ static void listen_loop_poll(config *cfg) {
    int delay = 1;

    for (;;) {
        gettimeofday(&tv, 0);
        gettimeofday(&tv, 0);  // TODO: clock_gettime
        if (tv.tv_sec != cfg->last_second) {
            tick_handler(cfg);
            cfg->last_second = tv.tv_sec;
+1 −1
Original line number Diff line number Diff line
@@ -288,7 +288,7 @@ void *listener_mainloop(void *arg) {

    while (!self->shutdown) {
        bool work_done = false;
        gettimeofday(&tv, NULL);
        gettimeofday(&tv, NULL);  // TODO: clock_gettime
        time_t cur_sec = tv.tv_sec;
        if (cur_sec != last_sec) {
            tick_handler(self);
+1 −1
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ void *sender_mainloop(void *arg) {
    while (!self->shutdown) {
        bool work = false;
        
        gettimeofday(&tv, NULL);
        gettimeofday(&tv, NULL);  // TODO: clock_gettime
        time_t cur_sec = tv.tv_sec;
        if (cur_sec != last_sec) {
            BUS_LOG(b, 5, LOG_SENDER, "entering tick handler", b->udata);
+1 −1
Original line number Diff line number Diff line
@@ -597,7 +597,7 @@ static void* KineticLogger_FlushThread(void* arg)

    while(!KineticLogggerAbortRequested) {
        sleep(KINETIC_LOGGER_SLEEP_TIME_SEC);
        gettimeofday(&tv, NULL);
        gettimeofday(&tv, NULL);  // TODO: clock_gettime
        curtime = tv.tv_sec;
        if ((curtime - lasttime) >= KINETIC_LOGGER_FLUSH_INTERVAL_SEC) {
            KineticLogger_FlushBuffer();