]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: introduce dbus properties WatchdogDevice and friends
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Sep 2022 20:05:04 +0000 (05:05 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 14 Sep 2022 12:13:59 +0000 (13:13 +0100)
Closes #24665.

man/org.freedesktop.systemd1.xml
src/core/dbus-manager.c
src/shared/watchdog.c
src/shared/watchdog.h

index 689ca3ec88fc14cd6e70acee7fcf22376f30f6d9..919df52135ac2c6a638e2f7343af5c9add53fb1b 100644 (file)
@@ -515,6 +515,16 @@ node /org/freedesktop/systemd1 {
       readonly i DefaultOOMScoreAdjust = ...;
       @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
       readonly s CtrlAltDelBurstAction = '...';
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly s WatchdogDevice = '...';
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly t WatchdogTimeoutUsec = ...;
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly t WatchdogPreTimeoutUsec = ...;
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly t WatchdogLastPingTimestamp = ...;
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly t WatchdogLastPingTimestampMonotonic = ...;
   };
   interface org.freedesktop.DBus.Peer { ... };
   interface org.freedesktop.DBus.Introspectable { ... };
@@ -766,6 +776,16 @@ node /org/freedesktop/systemd1 {
 
     <!--property CtrlAltDelBurstAction is not documented!-->
 
+    <!--property WatchdogDevice is not documented!-->
+
+    <!--property WatchdogTimeoutUsec is not documented!-->
+
+    <!--property WatchdogPreTimeoutUsec is not documented!-->
+
+    <!--property WatchdogLastPingTimestamp is not documented!-->
+
+    <!--property WatchdogLastPingTimestampMonotonic is not documented!-->
+
     <!--Autogenerated cross-references for systemd.directives, do not edit-->
 
     <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.systemd1.Manager"/>
@@ -1176,6 +1196,16 @@ node /org/freedesktop/systemd1 {
 
     <variablelist class="dbus-property" generated="True" extra-ref="CtrlAltDelBurstAction"/>
 
+    <variablelist class="dbus-property" generated="True" extra-ref="WatchdogDevice"/>
+
+    <variablelist class="dbus-property" generated="True" extra-ref="WatchdogTimeoutUsec"/>
+
+    <variablelist class="dbus-property" generated="True" extra-ref="WatchdogPreTimeoutUsec"/>
+
+    <variablelist class="dbus-property" generated="True" extra-ref="WatchdogLastPingTimestamp"/>
+
+    <variablelist class="dbus-property" generated="True" extra-ref="WatchdogLastPingTimestampMonotonic"/>
+
     <!--End of Autogenerated section-->
 
     <refsect2>
index 039f941b683baf573cf4bd197169dc0b0652e169..3486bab84bab0e27f0f26a4e63f203b5ebd469ab 100644 (file)
@@ -61,6 +61,11 @@ static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_timer_slack_nsec, "t", (uint6
 static BUS_DEFINE_PROPERTY_GET_REF(property_get_hashmap_size, "u", Hashmap *, hashmap_size);
 static BUS_DEFINE_PROPERTY_GET_REF(property_get_set_size, "u", Set *, set_size);
 static BUS_DEFINE_PROPERTY_GET(property_get_default_timeout_abort_usec, "t", Manager, manager_default_timeout_abort_usec);
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_device, "s", watchdog_get_device());
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_timeout, "t", watchdog_get_timeout());
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_pretimeout, "t", watchdog_get_pretimeout());
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_realtime, "t", watchdog_get_last_ping(CLOCK_REALTIME));
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_watchdog_last_ping_monotonic, "t", watchdog_get_last_ping(CLOCK_MONOTONIC));
 
 static int property_get_virtualization(
                 sd_bus *bus,
@@ -2783,6 +2788,11 @@ const sd_bus_vtable bus_manager_vtable[] = {
         SD_BUS_PROPERTY("DefaultOOMPolicy", "s", bus_property_get_oom_policy, offsetof(Manager, default_oom_policy), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("WatchdogDevice", "s", property_get_watchdog_device, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("WatchdogTimeoutUsec", "t", property_get_watchdog_timeout, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("WatchdogPreTimeoutUsec", "t", property_get_watchdog_pretimeout, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("WatchdogLastPingTimestamp", "t", property_get_watchdog_last_ping_realtime, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("WatchdogLastPingTimestampMonotonic", "t", property_get_watchdog_last_ping_monotonic, 0, SD_BUS_VTABLE_PROPERTY_CONST),
 
         SD_BUS_METHOD_WITH_ARGS("GetUnit",
                                 SD_BUS_ARGS("s", name),
index 2a3c299ccb0dd34ac4c2c73ef996dc98ee712f7f..690493a698dd01d61ab57190d5a376906cdf19fb 100644 (file)
@@ -119,7 +119,13 @@ static int watchdog_set_enable(bool enable) {
         return 0;
 }
 
-static int watchdog_get_timeout(void) {
+usec_t watchdog_get_timeout(void) {
+        if (watchdog_timeout == USEC_INFINITY)
+                return 0;
+        return watchdog_timeout;
+}
+
+static int watchdog_read_timeout(void) {
         int sec = 0;
 
         assert(watchdog_fd >= 0);
@@ -150,7 +156,13 @@ static int watchdog_set_timeout(void) {
         return 0;
 }
 
-static int watchdog_get_pretimeout(void) {
+usec_t watchdog_get_pretimeout(void) {
+        if (watchdog_pretimeout == USEC_INFINITY)
+                return 0;
+        return watchdog_pretimeout;
+}
+
+static int watchdog_read_pretimeout(void) {
         int sec = 0;
 
         assert(watchdog_fd >= 0);
@@ -185,11 +197,15 @@ static int watchdog_set_pretimeout(void) {
         }
 
         /* The set ioctl does not return the actual value set so get it now. */
-        (void) watchdog_get_pretimeout();
+        (void) watchdog_read_pretimeout();
 
         return 0;
 }
 
+usec_t watchdog_get_last_ping(clockid_t clock) {
+        return map_clock_usec(watchdog_last_ping, CLOCK_BOOTTIME, clock);
+}
+
 static int watchdog_ping_now(void) {
         assert(watchdog_fd >= 0);
 
@@ -241,7 +257,7 @@ static int update_pretimeout(void) {
                 r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                     "Cannot set watchdog pretimeout to %is (%s watchdog timeout of %is)",
                                     pt_sec, pt_sec == t_sec ? "same as" : "longer than", t_sec);
-                (void) watchdog_get_pretimeout();
+                (void) watchdog_read_pretimeout();
         } else
                 r = watchdog_set_pretimeout();
 
@@ -276,7 +292,7 @@ static int update_timeout(void) {
         }
 
         if (watchdog_timeout == USEC_INFINITY) {
-                r = watchdog_get_timeout();
+                r = watchdog_read_timeout();
                 if (r < 0)
                         return log_error_errno(r, "Failed to query watchdog HW timeout: %m");
         }
@@ -334,6 +350,10 @@ static int open_watchdog(void) {
         return r;
 }
 
+const char *watchdog_get_device(void) {
+        return watchdog_device;
+}
+
 int watchdog_set_device(const char *path) {
         int r;
 
index a537f8ae70dd3b12e553343eeda8d1260d5bbc9a..1242fbc4d9ea3221b93937d5a6527e1e5f403753 100644 (file)
@@ -6,6 +6,11 @@
 #include "time-util.h"
 #include "util.h"
 
+const char *watchdog_get_device(void);
+usec_t watchdog_get_timeout(void);
+usec_t watchdog_get_pretimeout(void);
+usec_t watchdog_get_last_ping(clockid_t clock);
+
 int watchdog_set_device(const char *path);
 int watchdog_setup(usec_t timeout);
 int watchdog_setup_pretimeout(usec_t usec);