summaryrefslogtreecommitdiffstats
path: root/watchdog.cpp
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-02-27 19:10:56 -0800
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-03-07 11:23:02 +0000
commit825f4981ef91031f3a9a549ff011ed9cc943a9b1 (patch)
tree5aeb2096c81f2c01e18f93f154ac89aed2c8f976 /watchdog.cpp
parent8cd3839207e56116412cc621315bb664ccc70b7d (diff)
downloadphosphor-watchdog-825f4981ef91031f3a9a549ff011ed9cc943a9b1.tar.gz
phosphor-watchdog-825f4981ef91031f3a9a549ff011ed9cc943a9b1.zip
watchdog: Rewrite timeoutHandler() to make disabling part of the timeout
This makes no functional changes to the user interface but make future code reworks shorter. Change-Id: Ibd57a5d1090588c8a7b2a67730660c3cf47c832e Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'watchdog.cpp')
-rw-r--r--watchdog.cpp84
1 files changed, 51 insertions, 33 deletions
diff --git a/watchdog.cpp b/watchdog.cpp
index 12631a6..24e5416 100644
--- a/watchdog.cpp
+++ b/watchdog.cpp
@@ -17,29 +17,30 @@ constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
// Enable or disable watchdog
bool Watchdog::enabled(bool value)
{
- if (this->enabled() != value)
+ if (!value)
{
- if (value)
- {
- // Start ONESHOT timer. Timer handles all in usec
- auto usec = duration_cast<microseconds>(
- milliseconds(this->interval()));
- // Update new expiration
- timer.start(usec);
-
- // Enable timer
- timer.setEnabled<std::true_type>();
-
- log<level::INFO>("watchdog: enabled and started",
- entry("INTERVAL=%llu", this->interval()));
- }
- else
- {
- timer.setEnabled<std::false_type>();
- timer.clearExpired();
- log<level::INFO>("watchdog: disabled");
- }
+ // Attempt to disable our timer if needed
+ tryDisable();
+
+ return false;
}
+ else if (!this->enabled())
+ {
+ // Start ONESHOT timer. Timer handles all in usec
+ auto usec = duration_cast<microseconds>(
+ milliseconds(this->interval()));
+
+ // Update new expiration
+ timer.clearExpired();
+ timer.start(usec);
+
+ // Enable timer
+ timer.setEnabled<std::true_type>();
+
+ log<level::INFO>("watchdog: enabled and started",
+ entry("INTERVAL=%llu", this->interval()));
+ }
+
return WatchdogInherits::enabled(value);
}
@@ -95,20 +96,37 @@ void Watchdog::timeOutHandler()
{
log<level::INFO>("watchdog: Timed out with no target",
entry("ACTION=%s", convertForMessage(action).c_str()));
- return;
+ }
+ else
+ {
+ auto method = bus.new_method_call(SYSTEMD_SERVICE,
+ SYSTEMD_ROOT,
+ SYSTEMD_INTERFACE,
+ "StartUnit");
+ method.append(target->second);
+ method.append("replace");
+
+ log<level::INFO>("watchdog: Timed out",
+ entry("ACTION=%s", convertForMessage(action).c_str()),
+ entry("TARGET=%s", target->second.c_str()));
+ bus.call_noreply(method);
+ }
+
+ tryDisable();
+}
+
+void Watchdog::tryDisable()
+{
+ if (timerEnabled())
+ {
+ timer.setEnabled<std::false_type>();
+
+ log<level::INFO>("watchdog: disabled");
}
- auto method = bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_ROOT,
- SYSTEMD_INTERFACE,
- "StartUnit");
- method.append(target->second);
- method.append("replace");
-
- log<level::INFO>("watchdog: Timed out",
- entry("ACTION=%s", convertForMessage(action).c_str()),
- entry("TARGET=%s", target->second.c_str()));
- bus.call_noreply(method);
+ // Make sure we accurately reflect our enabled state to the
+ // dbus interface.
+ WatchdogInherits::enabled(false);
}
} // namespace watchdog
OpenPOWER on IntegriCloud