From: Franck Bui Date: Mon, 6 Sep 2021 10:12:06 +0000 (+0200) Subject: core: watchdog_set_timeout() doesn't need to return the timeout value used by the HW X-Git-Tag: v250-rc1~670^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2628b98f0ca511a0d454940399aeaae156d16eeb;p=thirdparty%2Fsystemd.git core: watchdog_set_timeout() doesn't need to return the timeout value used by the HW The manager currently doesn't need it and if it does in the future an helper should probably be introduced instead. --- diff --git a/src/core/main.c b/src/core/main.c index 1ddbedd0781..d0495916459 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1539,7 +1539,7 @@ static int become_shutdown( /* If we reboot or kexec let's set the shutdown watchdog and * tell the shutdown binary to repeatedly ping it */ - r = watchdog_set_timeout(&watchdog_timer); + r = watchdog_set_timeout(watchdog_timer); watchdog_close(r < 0); /* Tell the binary how often to ping, ignore failure */ diff --git a/src/core/manager.c b/src/core/manager.c index 2b8270f1465..b82628be512 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3205,7 +3205,7 @@ void manager_set_watchdog(Manager *m, WatchdogType t, usec_t timeout) { if (t == WATCHDOG_RUNTIME) if (!timestamp_is_set(m->watchdog_overridden[WATCHDOG_RUNTIME])) { if (timestamp_is_set(timeout)) - (void) watchdog_set_timeout(&timeout); + (void) watchdog_set_timeout(timeout); else watchdog_close(true); } @@ -3224,11 +3224,10 @@ int manager_override_watchdog(Manager *m, WatchdogType t, usec_t timeout) { return 0; if (t == WATCHDOG_RUNTIME) { - usec_t *p; + usec_t usec = timestamp_is_set(timeout) ? timeout : m->watchdog[t]; - p = timestamp_is_set(timeout) ? &timeout : &m->watchdog[t]; - if (timestamp_is_set(*p)) - (void) watchdog_set_timeout(p); + if (timestamp_is_set(usec)) + (void) watchdog_set_timeout(usec); else watchdog_close(true); } diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index e0700b60139..c57dafbca54 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -96,23 +96,22 @@ int watchdog_set_device(char *path) { return r; } -int watchdog_set_timeout(usec_t *usec) { - int r; +int watchdog_set_timeout(usec_t timeout) { - watchdog_timeout = *usec; + /* Initialize the watchdog timeout with the caller value. This value is + * going to be updated by update_timeout() with the closest value + * supported by the driver */ + watchdog_timeout = timeout; - /* If we didn't open the watchdog yet and didn't get any explicit timeout value set, don't do - * anything */ + /* If we didn't open the watchdog yet and didn't get any explicit + * timeout value set, don't do anything */ if (watchdog_fd < 0 && watchdog_timeout == USEC_INFINITY) return 0; if (watchdog_fd < 0) - r = open_watchdog(); - else - r = update_timeout(); + return open_watchdog(); - *usec = watchdog_timeout; - return r; + return update_timeout(); } usec_t watchdog_runtime_wait(void) { diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h index b7587db3aba..08be44fd185 100644 --- a/src/shared/watchdog.h +++ b/src/shared/watchdog.h @@ -7,7 +7,7 @@ #include "util.h" int watchdog_set_device(char *path); -int watchdog_set_timeout(usec_t *usec); +int watchdog_set_timeout(usec_t timeout); int watchdog_ping(void); void watchdog_close(bool disarm); usec_t watchdog_runtime_wait(void); diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index a2ba96bf7c0..2387e279850 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -387,7 +387,7 @@ int main(int argc, char *argv[]) { log_warning_errno(r, "Failed to parse watchdog timeout '%s', ignoring: %m", watchdog_usec); else - (void) watchdog_set_timeout(&usec); + (void) watchdog_set_timeout(usec); } /* Lock us into memory */ diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c index cbef75fe07f..d94ac91d2cb 100644 --- a/src/test/test-watchdog.c +++ b/src/test/test-watchdog.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC; count = slow ? 5 : 3; - r = watchdog_set_timeout(&t); + r = watchdog_set_timeout(t); if (r < 0) log_warning_errno(r, "Failed to open watchdog: %m"); if (r == -EPERM)