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