diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index 0882a9bbc..f5f3b5459 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -202,6 +202,10 @@ #define TV_ETERNITY_MS (-1) #endif +/* delay between boot and first time wrap, in seconds */ +#ifndef BOOT_TIME_WRAP_SEC +#define BOOT_TIME_WRAP_SEC 20 +#endif /* we want to be able to detect time jumps. Fix the maximum wait time to a low * value so that we know the time has changed if we wait longer. */ diff --git a/src/clock.c b/src/clock.c index 75d2293ac..59ec173c1 100644 --- a/src/clock.c +++ b/src/clock.c @@ -267,6 +267,16 @@ void clock_init_process_date(void) now = after_poll = before_poll = date; global_now = ((ullong)date.tv_sec << 32) + (uint)date.tv_usec; global_now_ms = now.tv_sec * 1000 + now.tv_usec / 1000; + + /* force time to wrap 20s after boot: we first compute the time offset + * that once applied to the wall-clock date will make the local time + * wrap in 5 seconds. This offset is applied to the process-wide time, + * and will be used to recompute the local time, both of which will + * match and continue from this shifted date. + */ + now_offset = (uint64_t)(-(global_now_ms / 1000U) - BOOT_TIME_WRAP_SEC) << 32; + global_now += now_offset; + th_ctx->idle_pct = 100; clock_update_date(0, 1); }