]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
sync time periodically.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 7 Oct 2019 16:23:20 +0000 (12:23 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 7 Oct 2019 16:23:49 +0000 (12:23 -0400)
Which lets us catch time zone changes (e.g. daylight savings)
and clock drift

src/bin/radiusd.c
src/lib/util/time.c
src/lib/util/time.h

index 7a8c193c12b5bbdc99fab48d7af33d650ccab801..240bddb01179fb1980df06d2a860e65216055635 100644 (file)
@@ -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.
         */
index 9084a04aa912141a9bc2085e079afe48b6339385..9bc0dc476d1b1b22f795f2218315e0f3c2f23c18 100644 (file)
@@ -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;
index 8c0a334472cdeb8d28bf7bff7086f687e8a91614..29b9aff8f8e557ab113d1e1d6f0ee73ffe431a5b 100644 (file)
@@ -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