diff options
Diffstat (limited to 'sdevent/event.hpp')
-rw-r--r-- | sdevent/event.hpp | 32 |
1 files changed, 27 insertions, 5 deletions
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 @@ using Event = std::unique_ptr<sd_event, EventDeleter>; */ 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 @@ class Event /** @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 @@ class Event 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::Event(EventPtr l, std::false_type) : evt(l) 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()); } |