1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

pid1: introduce dbus properties WatchdogDevice and friends

Closes #24665.
This commit is contained in:
Yu Watanabe 2022-09-14 05:05:04 +09:00 committed by Luca Boccassi
parent 908eb7be58
commit 10f3f4ed01
4 changed files with 70 additions and 5 deletions

View 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>

View 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),

View 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;

View 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);