From: Chris Down Date: Tue, 26 May 2020 13:35:18 +0000 (+0100) Subject: service: Display updated WatchdogUSec from sd_notify X-Git-Tag: v246-rc1~274 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4793c31083031e729e6eb17b87b540a3944bba3b;p=thirdparty%2Fsystemd.git service: Display updated WatchdogUSec from sd_notify Suppose a service has WatchdogSec set to 2 seconds in its unit file. I then start the service and WatchdogUSec is set correctly: % systemctl --user show psi-notify -p WatchdogUSec WatchdogUSec=2s Now I call `sd_notify(0, "WATCHDOG_USEC=10000000")`. The new timer seems to have taken effect, since I only send `WATCHDOG=1` every 4 seconds, and systemd isn't triggering the watchdog handler. However, `systemctl show` still shows WatchdogUSec as 2s: % systemctl --user show psi-notify -p WatchdogUSec WatchdogUSec=2s This seems surprising, since this "original" watchdog timer isn't the one taking effect any more. This patch makes it so that we instead display the new watchdog timer after sd_notify(WATCHDOG_USEC): % systemctl --user show psi-notify -p WatchdogUSec WatchdogUSec=10s Fixes #15726. --- diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 984ef2459ef..11680f0d69c 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -28,6 +28,7 @@ static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_restart, service_restart, Servi static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_notify_access, notify_access, NotifyAccess); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_emergency_action, emergency_action, EmergencyAction); static BUS_DEFINE_PROPERTY_GET(property_get_timeout_abort_usec, "t", Service, service_timeout_abort_usec); +static BUS_DEFINE_PROPERTY_GET(property_get_watchdog_usec, "t", Service, service_get_watchdog_usec); static int property_get_exit_status_set( sd_bus *bus, @@ -101,7 +102,7 @@ const sd_bus_vtable bus_service_vtable[] = { SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Service, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("TimeoutAbortUSec", "t", property_get_timeout_abort_usec, 0, 0), SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Service, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("WatchdogUSec", "t", bus_property_get_usec, offsetof(Service, watchdog_usec), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("WatchdogUSec", "t", property_get_watchdog_usec, 0, 0), BUS_PROPERTY_DUAL_TIMESTAMP("WatchdogTimestamp", offsetof(Service, watchdog_timestamp), 0), SD_BUS_PROPERTY("PermissionsStartOnly", "b", bus_property_get_bool, offsetof(Service, permissions_start_only), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), /* 😷 deprecated */ SD_BUS_PROPERTY("RootDirectoryStartOnly", "b", bus_property_get_bool, offsetof(Service, root_directory_start_only), SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/core/service.c b/src/core/service.c index 6e2a82a2865..a824f2d6a00 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -198,15 +198,6 @@ static void service_stop_watchdog(Service *s) { s->watchdog_timestamp = DUAL_TIMESTAMP_NULL; } -static usec_t service_get_watchdog_usec(Service *s) { - assert(s); - - if (s->watchdog_override_enable) - return s->watchdog_override_usec; - - return s->watchdog_original_usec; -} - static void service_start_watchdog(Service *s) { usec_t watchdog_usec; int r; diff --git a/src/core/service.h b/src/core/service.h index b9c8036f225..3a84db14c47 100644 --- a/src/core/service.h +++ b/src/core/service.h @@ -200,6 +200,11 @@ static inline usec_t service_timeout_abort_usec(Service *s) { return s->timeout_abort_set ? s->timeout_abort_usec : s->timeout_stop_usec; } +static inline usec_t service_get_watchdog_usec(Service *s) { + assert(s); + return s->watchdog_override_enable ? s->watchdog_override_usec : s->watchdog_original_usec; +} + extern const UnitVTable service_vtable; int service_set_socket_fd(Service *s, int fd, struct Socket *socket, bool selinux_context_net);