+static const struct timespec time_delta = {
+ .tv_sec = DEFAULT_HEALTH_CHECK_DELTA_S,
+ .tv_nsec = DEFAULT_HEALTH_CHECK_DELTA_NS,
+};
+
+/*
+ * Set time difference in res from time_a and time_b.
+ */
+static void time_diff(const struct timespec *time_a,
+ const struct timespec *time_b, struct timespec *res)
+{
+ if (time_a->tv_nsec - time_b->tv_nsec < 0) {
+ res->tv_sec = time_a->tv_sec - time_b->tv_sec - 1;
+ res->tv_nsec = 1000000000L + time_a->tv_sec - time_b->tv_sec;
+ } else {
+ res->tv_sec = time_a->tv_sec - time_b->tv_sec;
+ res->tv_nsec = time_a->tv_nsec - time_b->tv_nsec;
+ }
+}
+
+/*
+ * Return true if time_a - time_b > diff, else false.
+ */
+static int time_diff_gt(const struct timespec *time_a,
+ const struct timespec *time_b, const struct timespec *diff)
+{
+ struct timespec res;
+
+ time_diff(time_a, time_b, &res);
+ time_diff(&res, diff, &res);
+
+ if (res.tv_sec > 0) {
+ return 1;
+ } else if (res.tv_sec == 0 && res.tv_nsec > 0) {
+ return 1;
+ }
+
+ return 0;
+}
+