]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: list-units: use TABLE_TIMESTAMP_RELATIVE_MONOTONIC
authorMike Yuan <me@yhndnzj.com>
Thu, 25 May 2023 10:23:17 +0000 (18:23 +0800)
committerMike Yuan <me@yhndnzj.com>
Fri, 26 May 2023 05:29:55 +0000 (13:29 +0800)
src/systemctl/systemctl-list-units.c

index 9be9510a2c431966bd0bd121d8c0498e419318d5..77ff836bb095be8c4725c9e2a0461515b14b375c 100644 (file)
@@ -536,9 +536,10 @@ static int get_next_elapse(
 static int get_last_trigger(
                 sd_bus *bus,
                 const char *path,
-                usec_t *last) {
+                dual_timestamp *last) {
 
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+        dual_timestamp t;
         int r;
 
         assert(bus);
@@ -553,10 +554,23 @@ static int get_last_trigger(
                         "LastTriggerUSec",
                         &error,
                         't',
-                        last);
+                        &t.realtime);
+        if (r < 0)
+                return log_error_errno(r, "Failed to get last trigger time: %s", bus_error_message(&error, r));
+
+        r = sd_bus_get_property_trivial(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        path,
+                        "org.freedesktop.systemd1.Timer",
+                        "LastTriggerUSecMonotonic",
+                        &error,
+                        't',
+                        &t.monotonic);
         if (r < 0)
                 return log_error_errno(r, "Failed to get last trigger time: %s", bus_error_message(&error, r));
 
+        *last = t;
         return 0;
 }
 
@@ -564,7 +578,7 @@ typedef struct TimerInfo {
         const char* machine;
         const char* id;
         usec_t next_elapse;
-        usec_t last_trigger;
+        dual_timestamp last_trigger;
         char **triggered;
 } TimerInfo;
 
@@ -623,8 +637,8 @@ static int output_timers_list(const TimerInfo *timers, size_t n_timers) {
                 r = table_add_many(table,
                                    TABLE_TIMESTAMP, t->next_elapse,
                                    TABLE_TIMESTAMP_LEFT, t->next_elapse,
-                                   TABLE_TIMESTAMP, t->last_trigger,
-                                   TABLE_TIMESTAMP_RELATIVE, t->last_trigger,
+                                   TABLE_TIMESTAMP, t->last_trigger.realtime,
+                                   TABLE_TIMESTAMP_RELATIVE_MONOTONIC, t->last_trigger.monotonic,
                                    TABLE_STRING, unit);
                 if (r < 0)
                         return table_log_add_error(r);
@@ -677,8 +691,8 @@ static int add_timer_info(
                 size_t *n_timers) {
 
         _cleanup_strv_free_ char **triggered = NULL;
-        dual_timestamp next = DUAL_TIMESTAMP_NULL;
-        usec_t m, last = 0;
+        dual_timestamp next, last;
+        usec_t m;
         int r;
 
         assert(bus);