]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
watchdog: no need to ping the device twice in watchdog_ping() if the device has just...
authorFranck Bui <fbui@suse.com>
Mon, 6 Sep 2021 10:42:50 +0000 (12:42 +0200)
committerFranck Bui <fbui@suse.com>
Wed, 15 Sep 2021 09:32:21 +0000 (11:32 +0200)
src/shared/watchdog.c

index c49972c8296afb764f1f4c5042462e1cfe31bf5c..98532dbcb47d4f78ffe98d7913149f9791954530 100644 (file)
@@ -138,11 +138,14 @@ usec_t watchdog_runtime_wait(void) {
 
 int watchdog_ping(void) {
         usec_t ntime;
-        int r;
 
         if (!timestamp_is_set(watchdog_timeout))
                 return 0;
 
+        if (watchdog_fd < 0)
+                /* open_watchdog() will automatically ping the device for us if necessary */
+                return open_watchdog();
+
         ntime = now(clock_boottime_or_monotonic());
 
         /* Never ping earlier than watchdog_timeout/4 and try to ping
@@ -153,12 +156,6 @@ int watchdog_ping(void) {
                         return 0;
         }
 
-        if (watchdog_fd < 0) {
-                r = open_watchdog();
-                if (r < 0)
-                        return r;
-        }
-
         if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0)
                 return log_warning_errno(errno, "Failed to ping hardware watchdog: %m");