bmc/general_systemd: Fix stale status files
If we run verification twice or terminate the state machine early from
the client, we can end up with stale files. Ensure the files are cleared
immediately before triggering.
Tested:
Ran on a system currently using status files and it now correctly
reports the verification status after two consecutive update runs.
Change-Id: I99590393c5ed292fe5fe52dc32f5ec4ff048a467
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/general_systemd.cpp b/bmc/general_systemd.cpp
index bcdda0d..8d91975 100644
--- a/bmc/general_systemd.cpp
+++ b/bmc/general_systemd.cpp
@@ -162,6 +162,24 @@
service, mode);
}
+bool SystemdWithStatusFile::trigger()
+{
+ if (SystemdNoFile::status() != ActionStatus::running)
+ {
+ try
+ {
+ std::ofstream ofs;
+ ofs.open(checkPath);
+ ofs << "unknown";
+ }
+ catch (const std::exception& e)
+ {
+ return false;
+ }
+ }
+ return SystemdNoFile::trigger();
+}
+
ActionStatus SystemdWithStatusFile::status()
{
// Assume a status based on job execution if there is no file
@@ -191,6 +209,10 @@
{
result = ActionStatus::failed;
}
+ else
+ {
+ result = ActionStatus::unknown;
+ }
}
return result;
diff --git a/bmc/general_systemd.hpp b/bmc/general_systemd.hpp
index a8d9a88..590b339 100644
--- a/bmc/general_systemd.hpp
+++ b/bmc/general_systemd.hpp
@@ -79,6 +79,7 @@
{
}
+ bool trigger() override;
ActionStatus status() override;
private: