Don't exit with error when hwmon dir is removed
There is a race condition between when an hwmon
directory is removed and systemd halting the
phosphor-hwmon application monitoring it. This
code change ensures the application does not return
an error in these cases.
Resolves openbmc/openbmc#1789
Change-Id: If4f032759c522aa811d4092e7a7d8ea275480e4a
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/sysfs.cpp b/sysfs.cpp
index 3ca2ec4..bc94b12 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -180,6 +180,18 @@
// errno should still reflect the error from the failing open
// or read system calls that got us here.
auto rc = errno;
+
+ // If the directory disappeared then this application should gracefully
+ // exit. There are race conditions between the unloading of a hwmon
+ // driver and the stopping of this service by systemd. To prevent
+ // this application from falsely failing in these scenarios, it will
+ // simply exit if the directory or file can not be found. It is up
+ // to the user(s) of this provided hwmon object to log the appropriate
+ // errors if the object disappears when it should not.
+ if (rc == ENOENT)
+ {
+ exit(0);
+ }
instancePath /= "device";
using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error;
report<ReadFailure>(