summaryrefslogtreecommitdiffstats
path: root/sdevent
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-19 16:15:04 -0400
committerPatrick Williams <patrick@stwcx.xyz>2017-08-02 20:18:19 +0000
commitd516c61b6fa55edc6ed55bd685686b12d5c876ac (patch)
tree459b4fbf8d7e99a3f8962368cb22330598106940 /sdevent
parent7cd75d7853f884176711c5f26f01fac695f02306 (diff)
downloadphosphor-fan-presence-d516c61b6fa55edc6ed55bd685686b12d5c876ac.tar.gz
phosphor-fan-presence-d516c61b6fa55edc6ed55bd685686b12d5c876ac.zip
Throw errors after sd_event api failures
Change-Id: Ie0635bc28fcd1a2fd96764674e15c71f1dcbe51a Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'sdevent')
-rw-r--r--sdevent/event.hpp32
-rw-r--r--sdevent/source.hpp22
2 files changed, 45 insertions, 9 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());
}
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 @@ using source = std::unique_ptr<sd_event_source, SourceDeleter>;
*/
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<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:
OpenPOWER on IntegriCloud