]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: watchdog_set_timeout() doesn't need to return the timeout value used by the HW
authorFranck Bui <fbui@suse.com>
Mon, 6 Sep 2021 10:12:06 +0000 (12:12 +0200)
committerFranck Bui <fbui@suse.com>
Wed, 15 Sep 2021 08:56:26 +0000 (10:56 +0200)
The manager currently doesn't need it and if it does in the future an helper
should probably be introduced instead.

src/core/main.c
src/core/manager.c
src/shared/watchdog.c
src/shared/watchdog.h
src/shutdown/shutdown.c
src/test/test-watchdog.c

index 1ddbedd0781ed795dba9768dd28cf0e81165868a..d0495916459208d38e2759ec912af09437445ad8 100644 (file)
@@ -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 */
index 2b8270f1465801e052e8222ea73da8e17f1bfd7b..b82628be512dd8da9ef2ce7af6b198477d6c9380 100644 (file)
@@ -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);
         }
index e0700b601395fcfe6b2ba3354424e52685f336c7..c57dafbca54bc7a9182ee309e20b3cbbf58d19be 100644 (file)
@@ -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) {
index b7587db3abada7e3b43aa7f7d5e63c0d88c82236..08be44fd1859141a45acf3be2e06c0f2e22a691d 100644 (file)
@@ -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);
index a2ba96bf7c032e338bf5f96a8aa3dcdb76f46a99..2387e2798502310be892469069a8b77c323c4f22 100644 (file)
@@ -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 */
index cbef75fe07ff7f73399c1d254ba2b34a193dcc48..d94ac91d2cbd65509bacb35dc6f4038102954ea4 100644 (file)
@@ -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)