Fix the PSU Service crash issue.

When entity-manager changes, PSU service will crash when recreating
PSU Sensors. Change delay time to 3s for PSU service has enough time
to finish last creating, change sensor monitoring time to 1s to avoid
sysfs file reading failure.

Tested:
When starting system or reset entity-manager, PSU service will not
crash.

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: I43e7f5207c137cd3601877af5313a3c340ee05f3
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index fc24704..d5f1b23 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -44,8 +44,8 @@
                      double max, double min) :
     Sensor(boost::replace_all_copy(sensorName, " ", "_"),
            std::move(_thresholds), sensorConfiguration, objectType, max, min),
-    objServer(objectServer), inputDev(io, open(path.c_str(), O_RDONLY)),
-    waitTimer(io), path(path), errCount(0),
+    objServer(objectServer), inputDev(io), waitTimer(io), path(path),
+    errCount(0),
 
     sensorFactor(factor)
 {
@@ -58,6 +58,14 @@
                   << sensorName << "\"\n";
     }
 
+    fd = open(path.c_str(), O_RDONLY);
+    if (fd < 0)
+    {
+        std::cerr << "PSU sensor failed to open file\n";
+        return;
+    }
+    inputDev.assign(fd);
+
     std::string dbusPath = sensorPathPrefix + sensorTypeName + name;
 
     sensorInterface = objectServer.add_interface(
@@ -83,8 +91,8 @@
 
 PSUSensor::~PSUSensor()
 {
-    inputDev.close();
     waitTimer.cancel();
+    inputDev.close();
     objServer.remove_interface(sensorInterface);
     objServer.remove_interface(thresholdInterfaceWarning);
     objServer.remove_interface(thresholdInterfaceCritical);
@@ -156,15 +164,7 @@
         errCount++;
     }
 
-    responseStream.clear();
-    inputDev.close();
-    int fd = open(path.c_str(), O_RDONLY);
-    if (fd < 0)
-    {
-        std::cerr << "Failed to open path " << path << "\n";
-        return;
-    }
-    inputDev.assign(fd);
+    lseek(fd, 0, SEEK_SET);
     waitTimer.expires_from_now(boost::posix_time::milliseconds(sensorPollMs));
     waitTimer.async_wait([&](const boost::system::error_code& ec) {
         if (ec == boost::asio::error::operation_aborted)