21255d
From 6cc0022115afbac9ac66c456b140601d90271687 Mon Sep 17 00:00:00 2001
21255d
From: Lennart Poettering <lennart@poettering.net>
21255d
Date: Mon, 23 Nov 2020 11:40:24 +0100
21255d
Subject: [PATCH] sd-event: split clock data allocation out of
21255d
 sd_event_add_time()
21255d
21255d
Just some simple refactoring, that will make things easier for us later.
21255d
But it looks better this way even without the later function reuse.
21255d
21255d
(cherry picked from commit 41c63f36c3352af8bebf03b6181f5d866431d0af)
21255d
21255d
Related: #1819868
21255d
---
21255d
 src/libsystemd/sd-event/sd-event.c | 34 ++++++++++++++++++++----------
21255d
 1 file changed, 23 insertions(+), 11 deletions(-)
21255d
21255d
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
21255d
index 0f507f18d8..dc78dc7291 100644
21255d
--- a/src/libsystemd/sd-event/sd-event.c
21255d
+++ b/src/libsystemd/sd-event/sd-event.c
21255d
@@ -1232,6 +1232,28 @@ static int time_exit_callback(sd_event_source *s, uint64_t usec, void *userdata)
21255d
         return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata));
21255d
 }
21255d
 
21255d
+static int setup_clock_data(sd_event *e, struct clock_data *d, clockid_t clock) {
21255d
+        int r;
21255d
+
21255d
+        assert(d);
21255d
+
21255d
+        if (d->fd < 0) {
21255d
+                r = event_setup_timer_fd(e, d, clock);
21255d
+                if (r < 0)
21255d
+                        return r;
21255d
+        }
21255d
+
21255d
+        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
21255d
+        if (r < 0)
21255d
+                return r;
21255d
+
21255d
+        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
21255d
+        if (r < 0)
21255d
+                return r;
21255d
+
21255d
+        return 0;
21255d
+}
21255d
+
21255d
 _public_ int sd_event_add_time(
21255d
                 sd_event *e,
21255d
                 sd_event_source **ret,
21255d
@@ -1265,20 +1287,10 @@ _public_ int sd_event_add_time(
21255d
         d = event_get_clock_data(e, type);
21255d
         assert(d);
21255d
 
21255d
-        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
21255d
-        if (r < 0)
21255d
-                return r;
21255d
-
21255d
-        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
21255d
+        r = setup_clock_data(e, d, clock);
21255d
         if (r < 0)
21255d
                 return r;
21255d
 
21255d
-        if (d->fd < 0) {
21255d
-                r = event_setup_timer_fd(e, d, clock);
21255d
-                if (r < 0)
21255d
-                        return r;
21255d
-        }
21255d
-
21255d
         s = source_new(e, !ret, type);
21255d
         if (!s)
21255d
                 return -ENOMEM;