host-restart: set restart reason on scheduling use

When the scheduling feature is the reason for a power on of the system,
set the RestartCause property appropriately.

This property is used by other software on some systems to guide
partition behaviors in the host code.

Tested:
- Utilize the scheduling feature to start a boot of the system and
  verified the RestartCause was set to ScheduledPowerOn

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I9f7e88ccf214d01a18c6641b0a016ff5576ccf5f
diff --git a/scheduled_host_transition.cpp b/scheduled_host_transition.cpp
index 06035aa..ed843cd 100644
--- a/scheduled_host_transition.cpp
+++ b/scheduled_host_transition.cpp
@@ -1,6 +1,7 @@
 #include "scheduled_host_transition.hpp"
 
 #include "utils.hpp"
+#include "xyz/openbmc_project/State/Host/server.hpp"
 
 #include <sys/timerfd.h>
 #include <unistd.h>
@@ -42,8 +43,10 @@
     sdbusplus::xyz::openbmc_project::ScheduledTime::Error::InvalidTime;
 using HostTransition =
     sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition;
+using HostState = sdbusplus::xyz::openbmc_project::State::server::Host;
 
 constexpr auto PROPERTY_TRANSITION = "RequestedHostTransition";
+constexpr auto PROPERTY_RESTART_CAUSE = "RestartCause";
 
 uint64_t ScheduledHostTransition::scheduledTime(uint64_t value)
 {
@@ -93,6 +96,16 @@
 {
     auto hostPath = std::string{HOST_OBJPATH} + '0';
 
+    // Set RestartCause to indicate this transition is occurring due to a
+    // scheduled host transition as long as it's not an off request
+    if (HostTransition::scheduledTransition() != HostState::Transition::Off)
+    {
+        info("Set RestartCause to scheduled power on reason");
+        auto resCause =
+            convertForMessage(HostState::RestartCause::ScheduledPowerOn);
+        utils::setProperty(bus, hostPath, HOST_BUSNAME, PROPERTY_RESTART_CAUSE,
+                           resCause);
+    }
     auto reqTrans = convertForMessage(HostTransition::scheduledTransition());
 
     utils::setProperty(bus, hostPath, HOST_BUSNAME, PROPERTY_TRANSITION,