richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 8fe5d9138039aafd314340b12d6d586d657d53a7 Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Wed, 29 Jun 2016 19:03:26 -0700
803fb7
Subject: [PATCH] sd-event: expose the event loop iteration counter via
803fb7
 sd_event_get_iteration()
803fb7
803fb7
This extends the existing event loop iteration counter to 64bit, and exposes it
803fb7
via a new function sd_event_get_iteration(). This is helpful for cases like
803fb7
issue #3612. After all, since we maintain the counter anyway, we might as well
803fb7
expose it.
803fb7
803fb7
(This also fixes an unrelated issue in the man page for sd_event_wait() where
803fb7
micro and milliseconds got mixed up)
803fb7
803fb7
Cherry-picked from: 7486322b99da5b4d2d00d35b310b035f936f7964
803fb7
Related: #1342173
803fb7
---
803fb7
 src/libsystemd/sd-event/sd-event.c | 14 +++++++++++---
803fb7
 src/systemd/sd-event.h             |  1 +
803fb7
 2 files changed, 12 insertions(+), 3 deletions(-)
803fb7
803fb7
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
803fb7
index 1f1e6fe91..9d48e5a49 100644
803fb7
--- a/src/libsystemd/sd-event/sd-event.c
803fb7
+++ b/src/libsystemd/sd-event/sd-event.c
803fb7
@@ -76,8 +76,8 @@ struct sd_event_source {
803fb7
         int64_t priority;
803fb7
         unsigned pending_index;
803fb7
         unsigned prepare_index;
803fb7
-        unsigned pending_iteration;
803fb7
-        unsigned prepare_iteration;
803fb7
+        uint64_t pending_iteration;
803fb7
+        uint64_t prepare_iteration;
803fb7
 
803fb7
         LIST_FIELDS(sd_event_source, sources);
803fb7
 
803fb7
@@ -169,7 +169,7 @@ struct sd_event {
803fb7
 
803fb7
         pid_t original_pid;
803fb7
 
803fb7
-        unsigned iteration;
803fb7
+        uint64_t iteration;
803fb7
         dual_timestamp timestamp;
803fb7
         usec_t timestamp_boottime;
803fb7
         int state;
803fb7
@@ -2689,3 +2689,11 @@ _public_ int sd_event_get_watchdog(sd_event *e) {
803fb7
 
803fb7
         return e->watchdog;
803fb7
 }
803fb7
+
803fb7
+_public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
803fb7
+        assert_return(e, -EINVAL);
803fb7
+        assert_return(!event_pid_changed(e), -ECHILD);
803fb7
+
803fb7
+        *ret = e->iteration;
803fb7
+        return 0;
803fb7
+}
803fb7
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
803fb7
index 25a10f99a..4957f3a32 100644
803fb7
--- a/src/systemd/sd-event.h
803fb7
+++ b/src/systemd/sd-event.h
803fb7
@@ -101,6 +101,7 @@ int sd_event_get_tid(sd_event *e, pid_t *tid);
803fb7
 int sd_event_get_exit_code(sd_event *e, int *code);
803fb7
 int sd_event_set_watchdog(sd_event *e, int b);
803fb7
 int sd_event_get_watchdog(sd_event *e);
803fb7
+int sd_event_get_iteration(sd_event *e, uint64_t *ret);
803fb7
 
803fb7
 sd_event_source* sd_event_source_ref(sd_event_source *s);
803fb7
 sd_event_source* sd_event_source_unref(sd_event_source *s);