From d516c61b6fa55edc6ed55bd685686b12d5c876ac Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Wed, 19 Jul 2017 16:15:04 -0400 Subject: Throw errors after sd_event api failures Change-Id: Ie0635bc28fcd1a2fd96764674e15c71f1dcbe51a Signed-off-by: Brad Bishop --- sdevent/event.hpp | 32 +++++++++++++++++++++++++++----- sdevent/source.hpp | 22 ++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'sdevent') 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 #include +#include +#include #include #include - -// TODO: openbmc/openbmc#1720 - add error handling for sd_event API failures +#include namespace sdevent { @@ -46,6 +47,10 @@ using Event = std::unique_ptr; */ 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(); + } } /** @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(); + } + 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(); + } + 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 +#include +#include #include - -// TODO: openbmc/openbmc#1720 - add error handling for sd_event API failures +#include namespace sdevent { @@ -36,6 +37,10 @@ using source = std::unique_ptr; */ 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 @@ class Source 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(); + } + 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(); + } } private: -- cgit v1.2.1