Add sys command for powercycle on host shutdown.

The new command will trigger a power cycle the next time the host shuts
down. This can exist in parallel with the existing mechanism to trigger
a power cycle after a specified time interval.

The implementation of host state detection and power cycling is platfrom
specific; the new command will just add a temporary file that marks the
system ready to powercycle on the next shutdown. Usually, a systemd unit
would be enabled by the presence of this file to handle the power
cycling process.

Signed-off-by: Shounak Mitra <shounak@google.com>
Change-Id: I0cc40307748fb996be3f6062d8cba1a4b5049683
diff --git a/handler.cpp b/handler.cpp
index f9a964d..4f1bc56 100644
--- a/handler.cpp
+++ b/handler.cpp
@@ -199,6 +199,20 @@
     }
 }
 
+static constexpr auto RESET_ON_SHUTDOWN_FILENAME = "/run/powercycle_on_s5";
+
+void Handler::psuResetOnShutdown() const
+{
+    std::ofstream ofs;
+    ofs.open(RESET_ON_SHUTDOWN_FILENAME, std::ofstream::out);
+    if (!ofs.good())
+    {
+        std::fprintf(stderr, "Unable to open file for output.\n");
+        throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
+    }
+    ofs.close();
+}
+
 std::string Handler::getEntityName(std::uint8_t id, std::uint8_t instance)
 {
     // Check if we support this Entity ID.