control: Correct subscribing/handling of signals

When subscribing to signals, a pointer to the signal packages should be
used for the location to store the list of signal packages. This way the
callback is bound to the pointer and not the local variable that was
then getting moved.

Also, in handling signal messages, since there could be more than one
signal package to check against the signal received, a rewind must be
done to the signal message so that additional signal packages can read
the message contents again.

Change-Id: Iddea2011d25068d6f71bdee91801537cd5994728
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index b0da04a..8973d7c 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -28,6 +28,8 @@
 #include "sdbusplus.hpp"
 #include "zone.hpp"
 
+#include <systemd/sd-bus.h>
+
 #include <nlohmann/json.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/manager.hpp>
@@ -655,9 +657,9 @@
 }
 
 void Manager::handleSignal(sdbusplus::message::message& msg,
-                           const std::vector<SignalPkg>& pkgs)
+                           const std::vector<SignalPkg>* pkgs)
 {
-    for (auto& pkg : pkgs)
+    for (auto& pkg : *pkgs)
     {
         // Handle the signal callback and only run the actions if the handler
         // updated the cache for the given SignalObject
@@ -669,6 +671,11 @@
             std::for_each(actions.begin(), actions.end(),
                           [](auto& action) { action.get()->run(); });
         }
+        // Only rewind message when not last package
+        if (&pkg != &pkgs->back())
+        {
+            sd_bus_message_rewind(msg.get(), true);
+        }
     }
 }