mainloop: Cache devpath at startup
Currently the devpath is determined after a bus error to make
a callout. Finding the path at startup is less prone to race
conditions around ENOENT on driver unload in the event of a
callout.
Change-Id: I8ce8d9f630c8b7ecc398082002aa113ab352d3cb
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 486a175..11f03a5 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -208,6 +208,7 @@
MainLoop::MainLoop(
sdbusplus::bus::bus&& bus,
const std::string& path,
+ const std::string& devPath,
const char* prefix,
const char* root)
: _bus(std::move(bus)),
@@ -215,6 +216,7 @@
_shutdown(false),
_hwmonRoot(),
_instance(),
+ _devPath(devPath),
_prefix(prefix),
_root(root),
state()
diff --git a/mainloop.hpp b/mainloop.hpp
index d4ef2c4..90f1efa 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -29,6 +29,7 @@
*
* @param[in] bus - sdbusplus bus client connection.
* @param[in] path - hwmon sysfs instance to manage
+ * @param[in] devPath - physical device sysfs path.
* @param[in] prefix - DBus busname prefix.
* @param[in] root - DBus sensors namespace root.
*
@@ -41,6 +42,7 @@
MainLoop(
sdbusplus::bus::bus&& bus,
const std::string& path,
+ const std::string& devPath,
const char* prefix,
const char* root);
@@ -67,6 +69,8 @@
std::string _hwmonRoot;
/** @brief hwmon sysfs instance. */
std::string _instance;
+ /** @brief physical device sysfs path. */
+ std::string _devPath;
/** @brief DBus busname prefix. */
const char* _prefix;
/** @brief DBus sensors namespace root. */
diff --git a/readd.cpp b/readd.cpp
index 95c6887..c7d0466 100644
--- a/readd.cpp
+++ b/readd.cpp
@@ -53,9 +53,17 @@
// Finished getting options out, so cleanup the parser.
options.reset();
+ // Determine the physical device sysfs path.
+ auto calloutPath = sysfs::findCalloutPath(path);
+ if (calloutPath.empty())
+ {
+ exit_with_error("Unable to determine callout path.", argv);
+ }
+
MainLoop loop(
sdbusplus::bus::new_default(),
path,
+ calloutPath,
BUSNAME_PREFIX,
SENSOR_ROOT);
loop.run();
diff --git a/test/test.cpp b/test/test.cpp
index 07aaef7..90a07c0 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -37,6 +37,7 @@
MainLoop loop(
sdbusplus::bus::new_default(),
dir,
+ dir,
"xyz.openbmc_project.Testing", "/testing");
auto threadMain = [](auto loop)