diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-05-25 21:06:33 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-06-08 18:48:36 +0530 |
commit | f9de54be38be17456dae06408ed93f3416a6621f (patch) | |
tree | 7d655ab336bf2be54ec812d6bc60ee1780a6702e /controller.cpp | |
parent | 413fd348514e5ab779a445f4f2cee84e9254b9a1 (diff) | |
download | phosphor-led-sysfs-f9de54be38be17456dae06408ed93f3416a6621f.tar.gz phosphor-led-sysfs-f9de54be38be17456dae06408ed93f3416a6621f.zip |
Work-around: Extract led name from device path
udev rule for leds subsystem in Witherspoon launches a systemd
service file with /sys/class/leds/$name. If the path is
sys-class-leds-rear-fault, systemd service file
interprets it as /sys/class/leds/rear/fault.
However, what is really needed by the service file is
/sys/class/leds/rear-fault.
This is a limitation in current systemd with template argument
containing hyphen.
Short term solution is to extract $name from path
and convert "/" to "-". It would then become:
/sys/class/leds/rear-fault and hence will work.
Refer: systemd/systemd#5072
Change-Id: I0acc11d039650857005ba75810e3ef6bcc4a3934
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'controller.cpp')
-rw-r--r-- | controller.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
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 |