diff options
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | controller.cpp | 24 |
2 files changed, 21 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac index 02472d0..6a08be3 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,11 @@ AC_ARG_VAR(OBJPATH, [The physical LED controller Dbus root]) AS_IF([test "x$OBJPATH" == "x"], [OBJPATH="/xyz/openbmc_project/led/physical"]) AC_DEFINE_UNQUOTED([OBJPATH], ["$OBJPATH"], [The physical LED controller Dbus root]) +# Platform device path for led subsystem. +AC_ARG_VAR(DEVPATH, [Physical led device path]) +AS_IF([test "x$DEVPATH" == "x"], [DEVPATH="/sys/class/leds/"]) +AC_DEFINE_UNQUOTED([DEVPATH], ["$DEVPATH"], [Physical led device path]) + # Create configured output AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/controller.cpp b/controller.cpp index d5728da..f0ba4c2 100644 --- a/controller.cpp +++ b/controller.cpp @@ -41,15 +41,23 @@ int main(int argc, char** argv) ExitWithError("Path not specified.", argv); } - // Extract the name of LED from path. - auto index = path.rfind("/"); - if (index == std::string::npos) - { - throw std::runtime_error("No Led in " + path); - } + // If the LED has a hyphen in the name like: "one-two", then it gets passed + // as /one/two/ as opposed to /one-two to the service file. There is a + // change needed in systemd to solve this issue and hence putting in this + // work-around. + + // Since this application always gets invoked as part of a udev rule, + // it is always guaranteed to get /sys/class/leds/one/two + // and we can go beyond leds/ to get the actual led name. + // Refer: systemd/systemd#5072 - // Remove the leading "/" - auto name = path.substr(index + 1); + // On an error, this throws an exception and terminates. + auto name = path.substr(strlen(DEVPATH)); + + // LED names may have a hyphen and that would be an issue for + // dbus paths and hence need to convert them to underscores. + std::replace(name.begin(), name.end(), '/', '-'); + path = std::move(DEVPATH + name); // Convert to lowercase just in case some are not and that // we follow lowercase all over |