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/PSUEvent.cpp b/src/PSUEvent.cpp
index bfe0776..4e5c5a7 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -135,10 +135,17 @@
     std::shared_ptr<bool> state, const std::string& psuName) :
     eventInterface(eventInterface),
     asserts(asserts), combineEvent(combineEvent), assertState(state),
-    errCount(0), path(path), eventName(eventName), waitTimer(io),
-    inputDev(io, open(path.c_str(), O_RDONLY)), psuName(psuName),
-    groupEventName(groupEventName)
+    errCount(0), path(path), eventName(eventName), waitTimer(io), inputDev(io),
+    psuName(psuName), groupEventName(groupEventName)
 {
+    fd = open(path.c_str(), O_RDONLY);
+    if (fd < 0)
+    {
+        std::cerr << "PSU sub event failed to open file\n";
+        return;
+    }
+    inputDev.assign(fd);
+
     auto found = logID.find(eventName);
     if (found == logID.end())
     {
@@ -174,8 +181,8 @@
 
 PSUSubEvent::~PSUSubEvent()
 {
-    inputDev.close();
     waitTimer.cancel();
+    inputDev.close();
 }
 
 void PSUSubEvent::handleResponse(const boost::system::error_code& err)
@@ -217,14 +224,7 @@
         updateValue(0);
         errCount++;
     }
-    responseStream.clear();
-    inputDev.close();
-    int fd = open(path.c_str(), O_RDONLY);
-    if (fd < 0)
-    {
-        return;
-    }
-    inputDev.assign(fd);
+    lseek(fd, 0, SEEK_SET);
     waitTimer.expires_from_now(boost::posix_time::milliseconds(eventPollMs));
     waitTimer.async_wait([&](const boost::system::error_code& ec) {
         if (ec == boost::asio::error::operation_aborted)