From: Curtis Klein Date: Fri, 5 May 2023 23:17:13 +0000 (-0700) Subject: watchdog: Allow the watchdog to be disabled at runtime X-Git-Tag: v255-rc1~857 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=902ea119e2cfebf527c2d9b423514a6093d55d17;p=thirdparty%2Fsystemd.git watchdog: Allow the watchdog to be disabled at runtime manager_{get|set|override}_watchdog check the validity of the new timeout or the overridden timeout values using timestamp_is_set which does not recognize "0" as a valid value. However since f16890f, "0" indicates a disabled watchdog and so is a value we should be able to configure in order to disable the watchdog. A value of USEC_INFINITY is considered a no-op. The behavior should be the same for all watchdog timeout configurations (runtime, pretimeout, and shutdown). --- diff --git a/src/core/manager.c b/src/core/manager.c index b7af1594497..29bb7cca1ab 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3419,7 +3419,7 @@ usec_t manager_get_watchdog(Manager *m, WatchdogType t) { if (MANAGER_IS_USER(m)) return USEC_INFINITY; - if (timestamp_is_set(m->watchdog_overridden[t])) + if (m->watchdog_overridden[t] != USEC_INFINITY) return m->watchdog_overridden[t]; return m->watchdog[t]; @@ -3435,17 +3435,18 @@ void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout) { if (m->watchdog[t] == timeout) return; - if (t == WATCHDOG_RUNTIME) { - if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) + if (m->watchdog_overridden[t] == USEC_INFINITY) { + if (t == WATCHDOG_RUNTIME) (void) watchdog_setup(timeout); - } else if (t == WATCHDOG_PRETIMEOUT) - if (m->watchdog_overridden[WATCHDOG_PRETIMEOUT] == USEC_INFINITY) + else if (t == WATCHDOG_PRETIMEOUT) (void) watchdog_setup_pretimeout(timeout); + } m->watchdog[t] = timeout; } void manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) { + usec_t usec; assert(m); @@ -3455,12 +3456,11 @@ void manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) { if (m->watchdog_overridden[t] == timeout) return; - if (t == WATCHDOG_RUNTIME) { - usec_t usec = timestamp_is_set(timeout) ? timeout : m->watchdog[t]; - + usec = (timeout == USEC_INFINITY) ? m->watchdog[t] : timeout; + if (t == WATCHDOG_RUNTIME) (void) watchdog_setup(usec); - } else if (t == WATCHDOG_PRETIMEOUT) - (void) watchdog_setup_pretimeout(timeout); + else if (t == WATCHDOG_PRETIMEOUT) + (void) watchdog_setup_pretimeout(usec); m->watchdog_overridden[t] = timeout; }