]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Print the actual value we're using for the watchdog
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 5 May 2017 20:47:49 +0000 (16:47 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 5 May 2017 20:53:52 +0000 (16:53 -0400)
src/include/libradius.h
src/lib/util/misc.c
src/main/process.c
src/main/radiusd.c

index 3ec28d557f84f6b112979713631e71a8e2f11ea4..9975a060a96e11ef22e435b70968eb00979b80a1 100644 (file)
@@ -358,6 +358,7 @@ ssize_t             fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inl
 size_t         fr_snprint_uint128(char *out, size_t outlen, uint128_t const num);
 int            fr_time_from_str(time_t *date, char const *date_str);
 void           fr_timeval_from_ms(struct timeval *out, uint64_t ms);
+void           fr_timeval_from_usec(struct timeval *out, uint64_t usec);
 void           fr_timeval_subtract(struct timeval *out, struct timeval const *end, struct timeval const *start);
 void           fr_timeval_add(struct timeval *out, struct timeval const *a, struct timeval const *b);
 void           fr_timeval_divide(struct timeval *out, struct timeval const *in, int divisor);
index 59b8fdfe19ee6dbf7ec2b0fbe30320b941feb4f0..e85ffa9035f8f244b16cdc29399ff7d99dcc0078 100644 (file)
@@ -948,6 +948,17 @@ void fr_timeval_from_ms(struct timeval *out, uint64_t ms)
        out->tv_usec = (ms % 1000) * 1000;
 }
 
+/** Convert a time specified in microseconds to a timeval
+ *
+ * @param[out] out     Where to write the result.
+ * @param[in] usec     To convert to a timeval struct.
+ */
+void fr_timeval_from_usec(struct timeval *out, uint64_t usec)
+{
+       out->tv_sec = usec / USEC;
+       out->tv_usec = (usec % USEC) * USEC;
+}
+
 /** Subtract one timeval from another
  *
  * @param[out] out Where to write difference.
index 970bc5b335ff623f6454a932fca5ec533f25467f..6b126d4fbb09481e972d2418ac15253b8f4d5b23 100644 (file)
@@ -54,7 +54,7 @@ extern pid_t radius_pid;
 extern fr_cond_t *debug_condition;
 
 #ifdef HAVE_SYSTEMD_WATCHDOG
-extern uint64_t sd_watchdog_interval;
+extern struct timeval sd_watchdog_interval;
 static fr_event_timer_t *sd_watchdog_ev;
 #endif
 
@@ -5066,16 +5066,15 @@ static int event_new_fd(rad_listen_t *this)
  *     Emit a systemd watchdog notification and reschedule the event.
  */
 #ifdef HAVE_SYSTEMD_WATCHDOG
-static void sd_watchdog_event(struct timeval *now, UNUSED void *ctx)
+static void sd_watchdog_event(struct timeval *now, void *ctx)
 {
        struct timeval when;
 
        DEBUG("Emitting systemd watchdog notification");
        sd_notify(0, "WATCHDOG=1");
 
-       memcpy(&when, now, sizeof(when));
-       tv_add(&when, sd_watchdog_interval / 2);
-       if (fr_event_timer_insert(el, sd_watchdog_event, NULL, &when, &sd_watchdog_ev) < 0) {
+       fr_timeval_add(&when, &sd_watchdog_interval, now);
+       if (fr_event_timer_insert(el, sd_watchdog_event, ctx, &when, &sd_watchdog_ev) < 0) {
                rad_panic("Failed to insert watchdog event");
        }
 }
@@ -5214,7 +5213,7 @@ int radius_event_init(TALLOC_CTX *ctx)
        if (!el) return 0;
 
 #ifdef HAVE_SYSTEMD_WATCHDOG
-       if ((int) sd_watchdog_interval > 0) {
+       if (sd_watchdog_interval.tv_sec || sd_watchdog_interval.tv_usec) {
                struct timeval now;
 
                fr_event_list_time(&now, el);
index b4cdd5b9bb55803bc6363f168a4fe3adddbd21b2..30e089235c6b146994c3f809a68071033eb72b12 100644 (file)
@@ -70,7 +70,7 @@ char const *radiusd_version = RADIUSD_VERSION_STRING_BUILD("FreeRADIUS");
 static pid_t radius_pid;
 
 #ifdef HAVE_SYSTEMD_WATCHDOG
-uint64_t sd_watchdog_interval = 0;
+struct timeval sd_watchdog_interval;
 #endif
 
 
@@ -420,10 +420,15 @@ int main(int argc, char *argv[])
         */
 #ifdef HAVE_SYSTEMD_WATCHDOG
        if (!check_config) {
-               if (sd_watchdog_enabled(0, &sd_watchdog_interval) > 0) {
-                       INFO("systemd watchdog interval is %d secs.\n", (int) sd_watchdog_interval / 1000000);
+               uint64_t usec;
+
+               if ((sd_watchdog_enabled(0, &usec) > 0) && (usec > 0)) {
+                       usec /= 2;
+                       fr_timeval_from_usec(&sd_watchdog_interval, usec);
+
+                       INFO("systemd watchdog interval is %pT secs", &sd_watchdog_interval);
                } else {
-                       INFO("systemd watchdog is disabled.\n");
+                       INFO("systemd watchdog is disabled");
                }
        }
 #endif