BMC: Block BMC reboots during Code Update

- Enable the service that blocks reboot within the constructor
  of ActivationBlockTransition, so that the user can't reboot BMC
  while code update is in progress.
- Once the code update is complete the destructor of
  ActivationBlockTransition will disable any reboot guard that
  prevents user from rebooting the BMC.

Tested: Verified that the user is unable to reboot during the activation
process and that journal logs are present to indicate why the user is
unable to reboot.

Resolves openbmc/openbmc#1944

Change-Id: Ia149a76bcf093b011fe243fc609ae83358a0f933
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index 8f7d8a1..a102bf3 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -249,6 +249,31 @@
     return;
 }
 
+void ActivationBlocksTransition::enableRebootGuard()
+{
+    log<level::INFO>("BMC image activating - BMC reboots are disabled.");
+
+    auto method = bus.new_method_call(
+            SYSTEMD_BUSNAME,
+            SYSTEMD_PATH,
+            SYSTEMD_INTERFACE,
+            "StartUnit");
+    method.append("reboot-guard-enable.service", "replace");
+    bus.call_noreply(method);
+}
+
+void ActivationBlocksTransition::disableRebootGuard()
+{
+    log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled.");
+
+    auto method = bus.new_method_call(
+            SYSTEMD_BUSNAME,
+            SYSTEMD_PATH,
+            SYSTEMD_INTERFACE,
+            "StartUnit");
+    method.append("reboot-guard-disable.service", "replace");
+    bus.call_noreply(method);
+}
 
 } // namespace updater
 } // namespace software
diff --git a/activation.hpp b/activation.hpp
index c62b747..b2b9aec 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -134,12 +134,14 @@
         {
             std::vector<std::string> interfaces({interface});
             bus.emit_interfaces_added(path.c_str(), interfaces);
+            enableRebootGuard();
         }
 
         ~ActivationBlocksTransition()
         {
             std::vector<std::string> interfaces({interface});
             bus.emit_interfaces_removed(path.c_str(), interfaces);
+            disableRebootGuard();
         }
 
     private:
@@ -148,6 +150,12 @@
                 "xyz.openbmc_project.Software.ActivationBlocksTransition";
         sdbusplus::bus::bus& bus;
         std::string path;
+
+        /** @brief Enables a Guard that blocks any BMC reboot commands */
+        void enableRebootGuard();
+
+        /** @brief Disables any guard that was blocking the BMC reboot */
+        void disableRebootGuard();
 };
 
 class ActivationProgress : public ActivationProgressInherit