[systemd-commits] dbus-unit.h systemd-interfaces.vala unit.c unit.h

Lennart Poettering lennart at kemper.freedesktop.org
Thu May 13 18:05:45 PDT 2010


 dbus-unit.h             |    4 ++++
 systemd-interfaces.vala |    2 ++
 unit.c                  |   26 +++++++++++++++++++++-----
 unit.h                  |    2 ++
 4 files changed, 29 insertions(+), 5 deletions(-)

New commits:
commit 173e382182d7f1ad2b132b6e923ef731d6affdf7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 14 03:05:38 2010 +0200

    unit: record inactive enter/exit timestamps to facilitate syslog lookups

diff --git a/dbus-unit.h b/dbus-unit.h
index 471f64c..db1716e 100644
--- a/dbus-unit.h
+++ b/dbus-unit.h
@@ -52,8 +52,10 @@
         "  <property name=\"ActiveState\" type=\"s\" access=\"read\"/>" \
         "  <property name=\"SubState\" type=\"s\" access=\"read\"/>"    \
         "  <property name=\"FragmentPath\" type=\"s\" access=\"read\"/>" \
+        "  <property name=\"InactiveExitTimestamp\" type=\"t\" access=\"read\"/>" \
         "  <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>" \
         "  <property name=\"ActiveExitTimestamp\" type=\"t\" access=\"read\"/>" \
+        "  <property name=\"InactiveEnterTimestamp\" type=\"t\" access=\"read\"/>" \
         "  <property name=\"CanReload\" type=\"b\" access=\"read\"/>"   \
         "  <property name=\"CanStart\" type=\"b\" access=\"read\"/>"    \
         "  <property name=\"Job\" type=\"(uo)\" access=\"read\"/>"      \
@@ -71,8 +73,10 @@
         { "org.freedesktop.systemd1.Unit", "ActiveState",          bus_unit_append_active_state,   "s",    u                               }, \
         { "org.freedesktop.systemd1.Unit", "SubState",             bus_unit_append_sub_state,      "s",    u                               }, \
         { "org.freedesktop.systemd1.Unit", "FragmentPath",         bus_property_append_string,     "s",    u->meta.fragment_path           }, \
+        { "org.freedesktop.systemd1.Unit", "InactiveExitTimestamp",bus_property_append_uint64,     "t",    &u->meta.inactive_exit_timestamp}, \
         { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_uint64,     "t",    &u->meta.active_enter_timestamp }, \
         { "org.freedesktop.systemd1.Unit", "ActiveExitTimestamp",  bus_property_append_uint64,     "t",    &u->meta.active_exit_timestamp  }, \
+        { "org.freedesktop.systemd1.Unit", "InActiveEnterTimestamp",bus_property_append_uint64,    "t",    &u->meta.inactive_enter_timestamp}, \
         { "org.freedesktop.systemd1.Unit", "CanStart",             bus_unit_append_can_start,      "b",    u                               }, \
         { "org.freedesktop.systemd1.Unit", "CanReload",            bus_unit_append_can_reload,     "b",    u                               }, \
         { "org.freedesktop.systemd1.Unit", "Job",                  bus_unit_append_job,            "(uo)", u                               }, \
diff --git a/systemd-interfaces.vala b/systemd-interfaces.vala
index a95dc01..72655d6 100644
--- a/systemd-interfaces.vala
+++ b/systemd-interfaces.vala
@@ -88,8 +88,10 @@ public interface Unit : DBus.Object {
         public abstract string active_state { owned get; }
         public abstract string sub_state { owned get; }
         public abstract string fragment_path { owned get; }
+        public abstract uint64 inactive_exit_timestamp { owned get; }
         public abstract uint64 active_enter_timestamp { owned get; }
         public abstract uint64 active_exit_timestamp { owned get; }
+        public abstract uint64 inactive_enter_timestamp { owned get; }
         public abstract bool can_start { owned get; }
         public abstract bool can_reload { owned get; }
         public abstract JobLink job { owned get; /* FIXME: this setter is a temporary fix to make valac not segfault */ set; }
diff --git a/unit.c b/unit.c
index fd6723f..7779753 100644
--- a/unit.c
+++ b/unit.c
@@ -558,7 +558,11 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
         char *p2;
         const char *prefix2;
         CGroupBonding *b;
-        char timestamp1[FORMAT_TIMESTAMP_MAX], timestamp2[FORMAT_TIMESTAMP_MAX];
+        char
+                timestamp1[FORMAT_TIMESTAMP_MAX],
+                timestamp2[FORMAT_TIMESTAMP_MAX],
+                timestamp3[FORMAT_TIMESTAMP_MAX],
+                timestamp4[FORMAT_TIMESTAMP_MAX];
 
         assert(u);
         assert(u->meta.type >= 0);
@@ -574,16 +578,20 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                 "%s\tInstance: %s\n"
                 "%s\tUnit Load State: %s\n"
                 "%s\tUnit Active State: %s\n"
+                "%s\tInactive Exit Timestamp: %s\n"
                 "%s\tActive Enter Timestamp: %s\n"
                 "%s\tActive Exit Timestamp: %s\n"
+                "%s\tInactive Enter Timestamp: %s\n"
                 "%s\tGC Check Good: %s\n",
                 prefix, u->meta.id,
                 prefix, unit_description(u),
                 prefix, strna(u->meta.instance),
                 prefix, unit_load_state_to_string(u->meta.load_state),
                 prefix, unit_active_state_to_string(unit_active_state(u)),
-                prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.active_enter_timestamp)),
-                prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_exit_timestamp)),
+                prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.inactive_exit_timestamp)),
+                prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_enter_timestamp)),
+                prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->meta.active_exit_timestamp)),
+                prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->meta.inactive_enter_timestamp)),
                 prefix, yes_no(unit_check_gc(u)));
 
         SET_FOREACH(t, u->meta.names, i)
@@ -908,6 +916,7 @@ static void retroactively_stop_dependencies(Unit *u) {
 
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
         bool unexpected = false;
+        usec_t ts;
 
         assert(u);
         assert(os < _UNIT_ACTIVE_STATE_MAX);
@@ -920,10 +929,17 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
          * this function will be called too and the utmp code below
          * relies on that! */
 
+        ts = now(CLOCK_REALTIME);
+
+        if (os == UNIT_INACTIVE && ns != UNIT_INACTIVE)
+                u->meta.inactive_exit_timestamp = ts;
+        else if (os != UNIT_INACTIVE && ns == UNIT_INACTIVE)
+                u->meta.inactive_enter_timestamp = ts;
+
         if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
-                u->meta.active_enter_timestamp = now(CLOCK_REALTIME);
+                u->meta.active_enter_timestamp = ts;
         else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
-                u->meta.active_exit_timestamp = now(CLOCK_REALTIME);
+                u->meta.active_exit_timestamp = ts;
 
         if (u->meta.job) {
 
diff --git a/unit.h b/unit.h
index 5b76a59..8f9d9e9 100644
--- a/unit.h
+++ b/unit.h
@@ -149,8 +149,10 @@ struct Meta {
          * the job for it */
         Job *job;
 
+        usec_t inactive_exit_timestamp;
         usec_t active_enter_timestamp;
         usec_t active_exit_timestamp;
+        usec_t inactive_enter_timestamp;
 
         /* Counterparts in the cgroup filesystem */
         CGroupBonding *cgroup_bondings;


More information about the systemd-commits mailing list