commit: Add call to Synchronize journal dbus method

Call the Synchronize method at the beginning of the Commit
function to request that all pending messages are written into
the journal.

Fixes: openbmc/openbmc#1297

Change-Id: Id0ab04ff0cb9b7eeac3b7c2aaeb8730a3b4ed524
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/log_manager.cpp b/log_manager.cpp
index d587ec4..6ae59fd 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -32,6 +32,15 @@
     // Length of 'TRANSACTION_ID=' string.
     constexpr const auto transactionIdVarOffset = transactionIdVarSize + 1;
 
+    // Flush all the pending log messages into the journal via Synchronize
+    constexpr auto JOURNAL_BUSNAME = "org.freedesktop.journal1";
+    constexpr auto JOURNAL_PATH = "/org/freedesktop/journal1";
+    constexpr auto JOURNAL_INTERFACE = "org.freedesktop.journal1";
+    auto bus = sdbusplus::bus::new_default();
+    auto method = bus.new_method_call(JOURNAL_BUSNAME, JOURNAL_PATH,
+                                      JOURNAL_INTERFACE, "Synchronize");
+    bus.call_noreply(method);
+
     sd_journal *j = nullptr;
     int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
     if (rc < 0)