commit a20babfd494848b877a23d83adf78989a040a824 Author: Jacob Welsh AuthorDate: Fri Nov 11 01:32:52 2022 +0000 Commit: Jacob Welsh CommitDate: Fri Nov 11 01:32:52 2022 +0000 Type: cleanup lib: cut two users of the magic TIME_T_MAX_BITS 1. Drop the unreliable and seemingly useless detection of forward time jumps, preserving detection of the more problematic backward jumps. 2. Drop gnarly fallback code for systems lacking timegm. diff --git a/src/lib/ioloop-private.h b/src/lib/ioloop-private.h index 799ca4d6d5..c5b5d672dd 100644 --- a/src/lib/ioloop-private.h +++ b/src/lib/ioloop-private.h @@ -25,7 +25,6 @@ struct ioloop { unsigned int max_fd_count; io_loop_time_moved_callback_t *time_moved_callback; - struct timeval next_max_time; uint64_t ioloop_wait_usecs; struct timeval wait_started; diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index e2488085ce..65ca027603 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -10,15 +10,6 @@ #include -/* Dovecot attempts to detect also when time suddenly jumps forwards. - This is done by getting the minimum timeout wait in epoll() (or similar) - and then seeing if the current time after epoll() is past the timeout. - This can't be very exact, so likely the difference is always at least - 1 microsecond. In high load situations it can be somewhat higher. - Dovecot generally doesn't have very important short timeouts, so to avoid - logging many warnings about this, use a rather high value. */ -#define IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS (100000) - time_t ioloop_time = 0; struct timeval ioloop_timeval; struct ioloop *current_ioloop = NULL; @@ -509,8 +500,6 @@ static int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r) return -1 for poll/epoll infinity. */ tv_r->tv_sec = INT_MAX / 1000; tv_r->tv_usec = 0; - ioloop->next_max_time.tv_sec = (1ULL << (TIME_T_MAX_BITS-1)) - 1; - ioloop->next_max_time.tv_usec = 0; return -1; } @@ -523,8 +512,6 @@ static int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r) tv_now.tv_sec = 0; msecs = timeout_get_wait_time(timeout, tv_r, &tv_now, FALSE); } - ioloop->next_max_time = tv_now; - timeval_add_msecs(&ioloop->next_max_time, msecs); /* update ioloop_timeval - this is meant for io_loop_handle_timeouts()'s ioloop_wait_usecs calculation. normally after this we go to the @@ -654,15 +641,6 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop) /* the callback may have slept, so check the time again. */ i_gettimeofday(&ioloop_timeval); } else { - diff_usecs = timeval_diff_usecs(&ioloop->next_max_time, - &ioloop_timeval); - if (unlikely(-diff_usecs >= IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS)) { - io_loops_timeouts_update(-diff_usecs); - /* time moved forwards */ - ioloop->time_moved_callback(&ioloop->next_max_time, - &ioloop_timeval); - i_assert(ioloop == current_ioloop); - } ioloop_add_wait_time(ioloop); } diff --git a/src/lib/utc-mktime.c b/src/lib/utc-mktime.c index e67c687a92..04af0c9562 100644 --- a/src/lib/utc-mktime.c +++ b/src/lib/utc-mktime.c @@ -26,7 +26,6 @@ static inline void adjust_leap_second(struct tm *tm) tm->tm_sec = 59; } -#ifdef HAVE_TIMEGM /* Normalization done by timegm is considered a failure here, since it means * the timestamp is not valid as-is. Leap second 60 is adjusted to 59 before * this though. */ @@ -42,38 +41,3 @@ time_t utc_mktime(const struct tm *tm) return (time_t)-1; return t; } -#else -time_t utc_mktime(const struct tm *tm) -{ - struct tm leap_adj_tm = *tm; - adjust_leap_second(&leap_adj_tm); - const struct tm *try_tm; - time_t t; - int bits, dir; - - /* we'll do a binary search across the entire valid time_t range. - when gmtime()'s output matches the tm parameter, we've found the - correct time_t value. this also means that if tm contains invalid - values, -1 is returned. */ -#ifdef TIME_T_SIGNED - t = 0; -#else - t = (time_t)1 << (TIME_T_MAX_BITS - 1); -#endif - for (bits = TIME_T_MAX_BITS - 2;; bits--) { - try_tm = gmtime(&t); - dir = tm_cmp(&leap_adj_tm, try_tm); - if (dir == 0) - return t; - if (bits < 0) - break; - - if (dir < 0) - t -= (time_t)1 << bits; - else - t += (time_t)1 << bits; - } - - return (time_t)-1; -} -#endif