Allow EAGAIN failures

Certain devices are known to return EAGAIN failures when read
too frequently, so be tolerant of them.

On startup, the code will retry for up to a second to get a good
first reading, and then in the main loop the code will just stick
with the current value if it fails that way.

Resolves openbmc/openbmc#2038

Change-Id: I7621aa30429c43276239982a03ec3eef02ce9c6e
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/sysfs.cpp b/sysfs.cpp
index b26c9ae..efdba92 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -153,7 +153,8 @@
                          const std::string& instance,
                          const std::string& type,
                          const std::string& id,
-                         const std::string& sensor)
+                         const std::string& sensor,
+                         bool throwDeviceBusy)
 {
     namespace fs = std::experimental::filesystem;
 
@@ -181,6 +182,11 @@
         // or read system calls that got us here.
         auto rc = errno;
 
+        if ((rc == EAGAIN) && throwDeviceBusy)
+        {
+            throw DeviceBusyException(fullPath);
+        }
+
         // 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