From 52c3bc708fb6a3eb68a3cac780b49192818bd409 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sat, 13 Nov 2021 10:33:08 +0900
Subject: [PATCH] event-util: introduce event_reset_time_relative()

Reference:https://github.com/systemd/systemd/commit/52c3bc708fb6a3eb68a3cac780b49192818bd409
Conflict:NA

---
 src/libsystemd/sd-event/event-util.c | 24 ++++++++++++++++++++++++
 src/libsystemd/sd-event/event-util.h | 26 ++++++++++++++++++++++----
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/src/libsystemd/sd-event/event-util.c b/src/libsystemd/sd-event/event-util.c
index 132796f..0e53406 100644
--- a/src/libsystemd/sd-event/event-util.c
+++ b/src/libsystemd/sd-event/event-util.c
@@ -84,6 +84,30 @@ int event_reset_time(
         return created;
 }
 
+int event_reset_time_relative(
+                sd_event *e,
+                sd_event_source **s,
+                clockid_t clock,
+                uint64_t usec,
+                uint64_t accuracy,
+                sd_event_time_handler_t callback,
+                void *userdata,
+                int64_t priority,
+                const char *description,
+                bool force_reset) {
+
+        usec_t usec_now;
+        int r;
+
+        assert(e);
+
+        r = sd_event_now(e, clock, &usec_now);
+        if (r < 0)
+                return log_debug_errno(r, "sd-event: Failed to get the current time: %m");
+
+        return event_reset_time(e, s, clock, usec_add(usec_now, usec), accuracy, callback, userdata, priority, description, force_reset);
+}
+
 int event_source_disable(sd_event_source *s) {
         if (!s)
                 return 0;
diff --git a/src/libsystemd/sd-event/event-util.h b/src/libsystemd/sd-event/event-util.h
index c8f97bc..64a4199 100644
--- a/src/libsystemd/sd-event/event-util.h
+++ b/src/libsystemd/sd-event/event-util.h
@@ -5,9 +5,27 @@
 
 #include "sd-event.h"
 
-int event_reset_time(sd_event *e, sd_event_source **s,
-                     clockid_t clock, uint64_t usec, uint64_t accuracy,
-                     sd_event_time_handler_t callback, void *userdata,
-                     int64_t priority, const char *description, bool force_reset);
+int event_reset_time(
+                sd_event *e,
+                sd_event_source **s,
+                clockid_t clock,
+                uint64_t usec,
+                uint64_t accuracy,
+                sd_event_time_handler_t callback,
+                void *userdata,
+                int64_t priority,
+                const char *description,
+                bool force_reset);
+int event_reset_time_relative(
+                sd_event *e,
+                sd_event_source **s,
+                clockid_t clock,
+                uint64_t usec,
+                uint64_t accuracy,
+                sd_event_time_handler_t callback,
+                void *userdata,
+                int64_t priority,
+                const char *description,
+                bool force_reset);
 int event_source_disable(sd_event_source *s);
 int event_source_is_enabled(sd_event_source *s);
-- 
2.33.0

