mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-27 14:03:43 +03:00
Merge pull request #21028 from poettering/watchdog-fixlets
pid1: various small watchdog tweaks and fixes
This commit is contained in:
commit
be0398bd4b
@ -144,7 +144,7 @@
|
||||
depending on hardware capabilities).</para>
|
||||
|
||||
<para>If <varname>RuntimeWatchdogSec=</varname> is set to a non-zero value, the watchdog hardware
|
||||
(<filename>/dev/watchdog</filename> or the path specified with <varname>WatchdogDevice=</varname> or
|
||||
(<filename>/dev/watchdog0</filename> or the path specified with <varname>WatchdogDevice=</varname> or
|
||||
the kernel option <varname>systemd.watchdog-device=</varname>) will be programmed to automatically
|
||||
reboot the system if it is not contacted within the specified timeout interval. The system manager
|
||||
will ensure to contact it at least once in half the specified timeout interval. This feature requires
|
||||
@ -182,7 +182,7 @@
|
||||
|
||||
<listitem><para>Configure the hardware watchdog device that the
|
||||
runtime and shutdown watchdog timers will open and use. Defaults
|
||||
to <filename>/dev/watchdog</filename>. This setting has no
|
||||
to <filename>/dev/watchdog0</filename>. This setting has no
|
||||
effect if a hardware watchdog is not available.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "path-util.h"
|
||||
#include "string-util.h"
|
||||
#include "time-util.h"
|
||||
#include "watchdog.h"
|
||||
@ -21,12 +22,10 @@ static usec_t watchdog_last_ping = USEC_INFINITY;
|
||||
|
||||
static int watchdog_set_enable(bool enable) {
|
||||
int flags = enable ? WDIOS_ENABLECARD : WDIOS_DISABLECARD;
|
||||
int r;
|
||||
|
||||
assert(watchdog_fd >= 0);
|
||||
|
||||
r = ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags);
|
||||
if (r < 0) {
|
||||
if (ioctl(watchdog_fd, WDIOC_SETOPTIONS, &flags) < 0) {
|
||||
if (!enable)
|
||||
return log_warning_errno(errno, "Failed to disable hardware watchdog, ignoring: %m");
|
||||
|
||||
@ -43,7 +42,7 @@ static int watchdog_set_enable(bool enable) {
|
||||
static int watchdog_get_timeout(void) {
|
||||
int sec = 0;
|
||||
|
||||
assert(watchdog_fd > 0);
|
||||
assert(watchdog_fd >= 0);
|
||||
|
||||
if (ioctl(watchdog_fd, WDIOC_GETTIMEOUT, &sec) < 0)
|
||||
return -errno;
|
||||
@ -107,7 +106,7 @@ static int update_timeout(void) {
|
||||
if (watchdog_timeout == USEC_INFINITY) {
|
||||
r = watchdog_get_timeout();
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "Failed to query watchdog HW timeout: %m");
|
||||
return log_error_errno(r, "Failed to query watchdog HW timeout: %m");
|
||||
}
|
||||
|
||||
r = watchdog_set_enable(true);
|
||||
@ -127,7 +126,13 @@ static int open_watchdog(void) {
|
||||
if (watchdog_fd >= 0)
|
||||
return 0;
|
||||
|
||||
fn = watchdog_device ?: "/dev/watchdog";
|
||||
/* Let's prefer new-style /dev/watchdog0 (i.e. kernel 3.5+) over classic /dev/watchdog. The former
|
||||
* has the benefit that we can easily find the matching directory in sysfs from it, as the relevant
|
||||
* sysfs attributes can only be found via /sys/dev/char/<major>:<minor> if the new-style device
|
||||
* major/minor is used, not the old-style. */
|
||||
fn = !watchdog_device || path_equal(watchdog_device, "/dev/watchdog") ?
|
||||
"/dev/watchdog0" : watchdog_device;
|
||||
|
||||
watchdog_fd = open(fn, O_WRONLY|O_CLOEXEC);
|
||||
if (watchdog_fd < 0)
|
||||
return log_debug_errno(errno, "Failed to open watchdog device %s, ignoring: %m", fn);
|
||||
|
Loading…
x
Reference in New Issue
Block a user