From 4d9a35b232f0bfabe961768f346d958399ff0dec Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Tue, 14 Nov 2017 22:33:03 -0500 Subject: Claim a stable well known busname Prior to this patch readd instances claim a busname with a format of: xyz.openbmc_project.Hwmon.Hwmon where N is the hwmon sysfs class instance. This is problematic for client applications that cache sensor object busname mappings for objects provided by readd. When readd instances restart (due to udev events) the hwmon sysfs class index may have changed, resulting in clients connecting to the wrong service instance. Address this by ensuring readd instances claim the same name every time they are started: xyz.openbmc_project.Hwmon-.Hwmon1 Where ID is a std::hash of the /sys/devices path backing the hwmon instance. Additionally, add a trailing API version as recommended best practice by the D-Bus specification. Change-Id: Idd0057ce883a49c1e828fb54fede27ea14022d6a Signed-off-by: Brad Bishop --- README.md | 15 +++++++++++++++ mainloop.cpp | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ac88a2..b6fce54 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,18 @@ To build this package, do the following steps: To full clean the repository again run `./bootstrap.sh clean`. ``` + +## D-Bus bus names + +``` +To enable the use of Linux features like cgroups prioritization and +udev/systemd control, one instance of phosphor-hwmon is intended to +be run per hwmon sysfs class instance. + +This requires an algorithm for selecting a stable, well-known D-Bus busname. + +The algorithm is -.Hwmon where PREFIX is an autoconf +configurable prefix (BUSNAME_PREFIX, xyz.openbmc_project by default), +ID is a std::hash of the /sys/devices path backing the hwmon class +instance, and N is the implemented phosphor-hwmon D-Bus API version. +``` diff --git a/mainloop.cpp b/mainloop.cpp index bf2cacc..61de673 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include @@ -373,8 +374,10 @@ void MainLoop::run() { std::string busname{_prefix}; - busname.append(1, '.'); - busname.append(_instance); + busname.append(1, '-'); + busname.append( + std::to_string(std::hash{}(_devPath))); + busname.append(".Hwmon1"); _bus.request_name(busname.c_str()); } -- cgit v1.2.1