main: Leverage sdeventplus common loop

This makes the memory leak workaround common as part of sdeventplus. Any
changes to that functionality can now be shared.

Change-Id: Iad83a2a20599e07c5d937b334a765cc365b089c5
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/main.cpp b/main.cpp
index c294a13..3b76870 100644
--- a/main.cpp
+++ b/main.cpp
@@ -36,6 +36,7 @@
 #include <sdeventplus/source/event.hpp>
 #include <sdeventplus/source/io.hpp>
 #include <sdeventplus/source/signal.hpp>
+#include <sdeventplus/utility/sdbus.hpp>
 #include <span>
 #include <stdplus/signal.hpp>
 #include <thread>
@@ -342,30 +343,16 @@
                 std::bind_front(PostCodeEventHandler, &reporter, verbose));
         }
         // Enable bus to handle incoming IO and bus events
-        bool done = false;
-        bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
-        auto intCb = [&done](sdeventplus::source::Signal& source,
-                             const struct signalfd_siginfo*) {
+        auto intCb = [](sdeventplus::source::Signal& source,
+                        const struct signalfd_siginfo*) {
             source.get_event().exit(0);
-            done = true;
         };
         stdplus::signal::block(SIGINT);
         sdeventplus::source::Signal(event, SIGINT, intCb).set_floating(true);
         stdplus::signal::block(SIGTERM);
         sdeventplus::source::Signal(event, SIGTERM, std::move(intCb))
             .set_floating(true);
-
-        while (!done)
-        {
-            // Process all outstanding bus events before running the loop.
-            // This prevents the sd-bus handling logic from leaking memory.
-            // TODO: Remove when upstream fixes this bug
-            while (bus.process_discard() > 0)
-                ;
-
-            // Run and never timeout
-            event.run(std::nullopt);
-        }
+        return sdeventplus::utility::loopWithBus(event, bus);
     }
     catch (const std::exception& e)
     {