From: Arran Cudbard-Bell Date: Fri, 5 May 2017 20:47:49 +0000 (-0400) Subject: Print the actual value we're using for the watchdog X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f39ee83db9fd6a06e45202aae68648e6326edca6;p=thirdparty%2Ffreeradius-server.git Print the actual value we're using for the watchdog --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 3ec28d557f8..9975a060a96 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -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); diff --git a/src/lib/util/misc.c b/src/lib/util/misc.c index 59b8fdfe19e..e85ffa9035f 100644 --- a/src/lib/util/misc.c +++ b/src/lib/util/misc.c @@ -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. diff --git a/src/main/process.c b/src/main/process.c index 970bc5b335f..6b126d4fbb0 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -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); diff --git a/src/main/radiusd.c b/src/main/radiusd.c index b4cdd5b9bb5..30e089235c6 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -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