Throw errors after sd_event api failures

Change-Id: Ie0635bc28fcd1a2fd96764674e15c71f1dcbe51a
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/sdevent/event.hpp b/sdevent/event.hpp
index 9f04dd0..53776ae 100644
--- a/sdevent/event.hpp
+++ b/sdevent/event.hpp
@@ -2,10 +2,11 @@
 
 #include <chrono>
 #include <memory>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
 #include <sdbusplus/bus.hpp>
 #include <systemd/sd-event.h>
-
-// TODO: openbmc/openbmc#1720 - add error handling for sd_event API failures
+#include <xyz/openbmc_project/Common/error.hpp>
 
 namespace sdevent
 {
@@ -46,6 +47,10 @@
  */
 class Event
 {
+    private:
+        using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+            Error::InternalFailure;
+
     public:
         /* Define all of the basic class operations:
          *     Not allowed:
@@ -84,7 +89,11 @@
         /** @brief Wait indefinitely for new event sources. */
         void loop()
         {
-            sd_event_loop(evt.get());
+            auto rc = sd_event_loop(evt.get());
+            if (rc < 0)
+            {
+                phosphor::logging::elog<InternalFailure>();
+            }
         }
 
         /** @brief Stop the loop. */
@@ -122,7 +131,12 @@
             using namespace std::chrono;
 
             uint64_t usec;
-            sd_event_now(evt.get(), CLOCK_MONOTONIC, &usec);
+            auto rc = sd_event_now(evt.get(), CLOCK_MONOTONIC, &usec);
+            if (rc < 0)
+            {
+                phosphor::logging::elog<InternalFailure>();
+            }
+
             microseconds d(usec);
             return steady_clock::time_point(d);
         }
@@ -151,8 +165,16 @@
 
 inline Event newDefault()
 {
+    using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+        Error::InternalFailure;
+
     sd_event* e = nullptr;
-    sd_event_default(&e);
+    auto rc = sd_event_default(&e);
+    if (rc < 0)
+    {
+        phosphor::logging::elog<InternalFailure>();
+    }
+
     return Event(e, std::false_type());
 }
 
diff --git a/sdevent/source.hpp b/sdevent/source.hpp
index e9e2a0c..be3a892 100644
--- a/sdevent/source.hpp
+++ b/sdevent/source.hpp
@@ -1,9 +1,10 @@
 #pragma once
 
 #include <memory>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/elog-errors.hpp>
 #include <systemd/sd-event.h>
-
-// TODO: openbmc/openbmc#1720 - add error handling for sd_event API failures
+#include <xyz/openbmc_project/Common/error.hpp>
 
 namespace sdevent
 {
@@ -36,6 +37,10 @@
  */
 class Source
 {
+    private:
+        using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+            Error::InternalFailure;
+
     public:
         /* Define all of the basic class operations:
          *     Not allowed:
@@ -75,14 +80,23 @@
         auto enabled()
         {
             int enabled;
-            sd_event_source_get_enabled(src.get(), &enabled);
+            auto rc = sd_event_source_get_enabled(src.get(), &enabled);
+            if (rc < 0)
+            {
+                phosphor::logging::elog<InternalFailure>();
+            }
+
             return enabled;
         }
 
         /** @brief Allow the source to generate events. */
         void enable(int enable)
         {
-            sd_event_source_set_enabled(src.get(), enable);
+            auto rc = sd_event_source_set_enabled(src.get(), enable);
+            if (rc < 0)
+            {
+                phosphor::logging::elog<InternalFailure>();
+            }
         }
 
     private: