From: Alan T. DeKok Date: Mon, 7 Oct 2019 16:23:20 +0000 (-0400) Subject: sync time periodically. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed2d64c3a7596b5183d02d76acf4cf544e25ea2c;p=thirdparty%2Ffreeradius-server.git sync time periodically. Which lets us catch time zone changes (e.g. daylight savings) and clock drift --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index 7a8c193c12b..240bddb0117 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -150,6 +150,17 @@ do { \ goto cleanup; \ } while (0) +static fr_event_timer_t const *fr_time_sync_ev = NULL; + +static void fr_time_sync_event(fr_event_list_t *el, UNUSED fr_time_t now, UNUSED void *uctx) +{ + fr_time_delta_t when = NSEC; + + (void) fr_event_timer_in(el, el, &fr_time_sync_ev, when, fr_time_sync_event, NULL); + (void) fr_time_sync(); +} + + /* * The main guy. */ @@ -174,6 +185,7 @@ int main(int argc, char *argv[]) void *pool_page_start = NULL, *pool_page_end = NULL; bool do_mprotect; dl_module_loader_t *dl_modules = NULL; + bool sync_time = true; /* * Setup talloc callbacks so we get useful errors @@ -371,6 +383,7 @@ int main(int argc, char *argv[]) break; case 'X': + sync_time = false; config->spawn_workers = false; config->daemonize = false; fr_debug_lvl += 2; @@ -851,6 +864,15 @@ int main(int argc, char *argv[]) DEBUG("Global memory protected"); } + /* + * Sync timers normally, but not when running with + * `radiusd -X`. For debug mode, we don't really care if + * the times are off a little bit. And skipping this + * timer means that we don't pollute the debug output + * with lots of "waking up in 1s". + */ + if (sync_time) fr_time_sync_event(main_loop_event_list(), fr_time(), NULL); + /* * Process requests until HUP or exit. */ diff --git a/src/lib/util/time.c b/src/lib/util/time.c index 9084a04aa91..9bc0dc476d1 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -71,7 +71,7 @@ static uint64_t our_mach_epoch; * - 0 on success. * - -1 on failure. */ -static inline int fr_time_sync(void) +int fr_time_sync(void) { struct tm tm; time_t now; diff --git a/src/lib/util/time.h b/src/lib/util/time.h index 8c0a334472c..29b9aff8f8e 100644 --- a/src/lib/util/time.h +++ b/src/lib/util/time.h @@ -110,6 +110,7 @@ typedef struct { #define USEC (1000000) int fr_time_start(void); +int fr_time_sync(void); fr_time_t fr_time(void); #define fr_unix_time_from_nsec(_x) _x