Add sensor instance id command line argument.
Introduce `-i|--sensor-id` flag to explicitly set sensor
suffix for dbus name.
Sample usage:
phosphor-hwmon-readd -i test_sensor_id -o /apb/...
Will register the service with the following busname:
xyz.openbmc_project.Hwmon-test_sensor_id.Hwmon1
This change required as a part of privilege separation work:
https://github.com/openbmc/openbmc/issues/3383
Signed-off-by: Anton D. Kachalov <gmouse@google.com>
Change-Id: I48ff9c3efe0edb84718ff8f695e7e932af5445de
diff --git a/mainloop.cpp b/mainloop.cpp
index 40c429a..75c8c12 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -309,11 +309,13 @@
MainLoop::MainLoop(sdbusplus::bus::bus&& bus, const std::string& param,
const std::string& path, const std::string& devPath,
const char* prefix, const char* root,
+ const std::string& instanceId,
const hwmonio::HwmonIOInterface* ioIntf) :
_bus(std::move(bus)),
_manager(_bus, root), _pathParam(param), _hwmonRoot(), _instance(),
_devPath(devPath), _prefix(prefix), _root(root), _state(),
- _ioAccess(ioIntf), _event(sdeventplus::Event::get_default()),
+ _instanceId(instanceId), _ioAccess(ioIntf),
+ _event(sdeventplus::Event::get_default()),
_timer(_event, std::bind(&MainLoop::read, this))
{
// Strip off any trailing slashes.
@@ -403,9 +405,13 @@
{
std::stringstream ss;
- ss << _prefix << "-"
- << std::to_string(std::hash<std::string>{}(_devPath + _pathParam))
- << ".Hwmon1";
+ std::string id = _instanceId;
+ if (id.empty())
+ {
+ id =
+ std::to_string(std::hash<std::string>{}(_devPath + _pathParam));
+ }
+ ss << _prefix << "-" << id << ".Hwmon1";
_bus.request_name(ss.str().c_str());
}