daandemeyer / rpms / systemd

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