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);
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.
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
* 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");
}
}
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);
static pid_t radius_pid;
#ifdef HAVE_SYSTEMD_WATCHDOG
-uint64_t sd_watchdog_interval = 0;
+struct timeval sd_watchdog_interval;
#endif
*/
#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