]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/watchdog.c
resolved: rework parsing of /etc/hosts
[thirdparty/systemd.git] / src / shared / watchdog.c
index 9d39beb3404deee679733c33f1d14ea43da890bc..c423af6917a534e164d303d6e442237d394b3330 100644 (file)
@@ -1,34 +1,20 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+/* SPDX-License-Identifier: LGPL-2.1+ */
 
-/***
-  This file is part of systemd.
-
-  Copyright 2012 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <sys/ioctl.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
+#include <syslog.h>
 #include <unistd.h>
 #include <linux/watchdog.h>
 
-#include "watchdog.h"
+#include "fd-util.h"
 #include "log.h"
+#include "string-util.h"
+#include "time-util.h"
+#include "watchdog.h"
 
 static int watchdog_fd = -1;
+static char *watchdog_device = NULL;
 static usec_t watchdog_timeout = USEC_INFINITY;
 
 static int update_timeout(void) {
@@ -50,7 +36,7 @@ static int update_timeout(void) {
                 int sec, flags;
                 char buf[FORMAT_TIMESPAN_MAX];
 
-                sec = (int) ((watchdog_timeout + USEC_PER_SEC - 1) / USEC_PER_SEC);
+                sec = (int) DIV_ROUND_UP(watchdog_timeout, USEC_PER_SEC);
                 r = ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &sec);
                 if (r < 0)
                         return log_warning_errno(errno, "Failed to set timeout to %is: %m", sec);
@@ -82,7 +68,8 @@ static int open_watchdog(void) {
         if (watchdog_fd >= 0)
                 return 0;
 
-        watchdog_fd = open("/dev/watchdog", O_WRONLY|O_CLOEXEC);
+        watchdog_fd = open(watchdog_device ?: "/dev/watchdog",
+                           O_WRONLY|O_CLOEXEC);
         if (watchdog_fd < 0)
                 return -errno;
 
@@ -94,6 +81,10 @@ static int open_watchdog(void) {
         return update_timeout();
 }
 
+int watchdog_set_device(char *path) {
+        return free_and_strdup(&watchdog_device, path);
+}
+
 int watchdog_set_timeout(usec_t *usec) {
         int r;