monitor: support systemd delay getting on dbus

Testing has shown that systemd does not always get registered on dbus
before the phosphor-systemd-target-monitor application starts up and
calls into systemd dbus interfaces. The code in this commit ensures the
application handles both the scenario where it is available on startup
and the scenario where the interfaces becomes available after startup.

Tested:
Verified application started and subscribed to systemd signals in both
scenarios described above.

Resolves openbmc/phosphor-state-manager#10
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I6594466681cd66f90ae27a6e935085a17120457a
diff --git a/systemd_target_signal.hpp b/systemd_target_signal.hpp
index d0719a8..3864602 100644
--- a/systemd_target_signal.hpp
+++ b/systemd_target_signal.hpp
@@ -39,7 +39,12 @@
                 sdbusplus::bus::match::rules::interface(
                     "org.freedesktop.systemd1.Manager"),
             std::bind(std::mem_fn(&SystemdTargetLogging::systemdUnitChange),
-                      this, std::placeholders::_1))
+                      this, std::placeholders::_1)),
+        systemdNameOwnedChangedSignal(
+            bus, sdbusplus::bus::match::rules::nameOwnerChanged(),
+            std::bind(
+                std::mem_fn(&SystemdTargetLogging::processNameChangeSignal),
+                this, std::placeholders::_1))
     {
     }
 
@@ -82,6 +87,16 @@
      */
     void systemdUnitChange(sdbusplus::message::message& msg);
 
+    /** @brief Wait for systemd to show up on dbus
+     *
+     * Once systemd is on dbus, this application can subscribe to systemd
+     * signal changes
+     *
+     * @param[in]  msg       - Data associated with subscribed signal
+     *
+     */
+    void processNameChangeSignal(sdbusplus::message::message& msg);
+
     /** @brief Systemd targets to monitor and error logs to create */
     const TargetErrorData& targetData;
 
@@ -90,6 +105,9 @@
 
     /** @brief Used to subscribe to dbus systemd JobRemoved signals **/
     sdbusplus::bus::match_t systemdJobRemovedSignal;
+
+    /** @brief Used to know when systemd has registered on dbus **/
+    sdbusplus::bus::match_t systemdNameOwnedChangedSignal;
 };
 
 } // namespace manager