From ba7b5fea818f65949cd074de9322094d3c54fb7b Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Wed, 25 Apr 2018 15:26:10 -0500 Subject: Throw custom exceptions on D-Bus method failures All 3 fan applications - control, monitor, and presence have cases where it is expected that a getProperty call may fail because a sensor is missing. While the applications already handle this, the InternalFailure exception that was being thrown by the underlying call generates log entries that make it look like something bad happened. The custom exceptions now being thrown do not log anything on creation, but store all of the failing information so that any callers could still log the info if they wanted to. Tested: Boot a water cooled Witherspoon and see the fan presence and monitor applications not look like they are failing. Boot a system without the fan hwmon running, and see fan-control-init still show the fails. Change-Id: Ifd8ad6e3deb492bbaf33f12c7258125dce1e5ea8 Signed-off-by: Matt Spinler --- control/functor.hpp | 6 ++---- control/main.cpp | 44 ++++++++++++++++++++++++++++++++------------ control/matches.hpp | 4 +--- control/zone.cpp | 2 +- 4 files changed, 36 insertions(+), 20 deletions(-) (limited to 'control') diff --git a/control/functor.hpp b/control/functor.hpp index 0a2b955..2ca047c 100644 --- a/control/functor.hpp +++ b/control/functor.hpp @@ -15,8 +15,6 @@ class Zone; using namespace phosphor::fan; using namespace sdbusplus::bus::match; using namespace phosphor::logging; -using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: - Error::InternalFailure; /** * @brief Create a handler function object @@ -115,7 +113,7 @@ struct PropertyChanged _property); _handler(zone, std::forward(val)); } - catch (const InternalFailure& ife) + catch (const util::DBusError& e) { // Property will not be used unless a property changed // signal message is received for this property. @@ -397,7 +395,7 @@ struct NameOwnerChanged "NameHasOwner", name); } - catch (const InternalFailure& ife) + catch (const util::DBusMethodError& e) { // Failed to get service name owner state hasOwner = false; diff --git a/control/main.cpp b/control/main.cpp index cde71d0..dd9330d 100644 --- a/control/main.cpp +++ b/control/main.cpp @@ -18,6 +18,7 @@ #include "argument.hpp" #include "manager.hpp" #include "event.hpp" +#include "sdbusplus.hpp" using namespace phosphor::fan::control; using namespace phosphor::logging; @@ -64,22 +65,41 @@ int main(int argc, char* argv[]) //handle both sd_events (for the timers) and dbus signals. bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); - Manager manager(bus, eventPtr, mode); + try + { + Manager manager(bus, eventPtr, mode); - //Init mode will just set fans to max and delay - if (mode == Mode::init) + //Init mode will just set fans to max and delay + if (mode == Mode::init) + { + manager.doInit(); + return 0; + } + else + { + r = sd_event_loop(eventPtr.get()); + if (r < 0) + { + log("Failed call to sd_event_loop", + entry("ERROR=%s", strerror(-r))); + } + } + } + //Log the useful metadata on these exceptions and let the app + //return -1 so it is restarted without a core dump. + catch (phosphor::fan::util::DBusServiceError& e) { - manager.doInit(); - return 0; + log("Uncaught DBus service lookup failure exception", + entry("PATH=%s", e.path.c_str()), + entry("INTERFACE=%s", e.interface.c_str())); } - else + catch (phosphor::fan::util::DBusMethodError& e) { - r = sd_event_loop(eventPtr.get()); - if (r < 0) - { - log("Failed call to sd_event_loop", - entry("ERROR=%s", strerror(-r))); - } + log("Uncaught DBus method failure exception", + entry("BUSNAME=%s", e.busName.c_str()), + entry("PATH=%s", e.path.c_str()), + entry("INTERFACE=%s", e.interface.c_str()), + entry("METHOD=%s", e.method.c_str())); } return -1; diff --git a/control/matches.hpp b/control/matches.hpp index ccacbc4..c3b4006 100644 --- a/control/matches.hpp +++ b/control/matches.hpp @@ -14,8 +14,6 @@ namespace match using namespace phosphor::fan; using namespace sdbusplus::bus::match; -using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: - Error::InternalFailure; /** * @brief A match function that constructs a PropertiesChanged match string @@ -77,7 +75,7 @@ inline auto nameOwnerChanged(const std::string& obj, const std::string& iface) { noc = rules::nameOwnerChanged(util::SDBusPlus::getService(obj, iface)); } - catch (const InternalFailure& ife) + catch (const util::DBusError& e) { // Unable to construct NameOwnerChanged match string } diff --git a/control/zone.cpp b/control/zone.cpp index 325a5b8..f4c50d9 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -196,7 +196,7 @@ void Zone::setServices(const Group* group) "NameHasOwner", name); } - catch (const InternalFailure& ife) + catch (const util::DBusMethodError& e) { // Failed to get service name owner state hasOwner = false; -- cgit v1.2.1