]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: add helper for TimersMonotonic property
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Jun 2025 14:14:44 +0000 (16:14 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 17:53:40 +0000 (19:53 +0200)
src/shared/bus-unit-util.c

index 62df0f5e36d38e66cf9dcf9817c1a7b562a0424e..424218692f299e3911960ea42675fae7909f073f 100644 (file)
@@ -2184,6 +2184,25 @@ static int bus_append_listen(sd_bus_message *m, const char *field, const char *e
         return 1;
 }
 
+static int bus_append_timers_monotonic(sd_bus_message *m, const char *field, const char *eq) {
+        int r;
+
+        if (isempty(eq))
+                r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 0);
+        else {
+                usec_t t;
+                r = parse_sec(eq, &t);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
+
+                r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 1, field, t);
+        }
+        if (r < 0)
+                return bus_log_create_error(r);
+
+        return 1;
+}
+
 static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
         if (STR_IN_SET(field, "DevicePolicy",
                               "Slice",
@@ -2828,22 +2847,8 @@ static int bus_append_timer_property(sd_bus_message *m, const char *field, const
                               "OnBootSec",
                               "OnStartupSec",
                               "OnUnitActiveSec",
-                              "OnUnitInactiveSec")) {
-                if (isempty(eq))
-                        r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 0);
-                else {
-                        usec_t t;
-                        r = parse_sec(eq, &t);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to parse %s=%s: %m", field, eq);
-
-                        r = sd_bus_message_append(m, "(sv)", "TimersMonotonic", "a(st)", 1, field, t);
-                }
-                if (r < 0)
-                        return bus_log_create_error(r);
-
-                return 1;
-        }
+                              "OnUnitInactiveSec"))
+                return bus_append_timers_monotonic(m, field, eq);
 
         if (streq(field, "OnCalendar")) {
                 if (isempty(eq))