attn: Add wait for power fault handling

Added a 10 second delay between checkstop detection and call to analyzer
so that power fault handler logic can intervene before analyzer begins
logging  events.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I13d36e9fed35ff8af690a5f38bf4476027a4fea2
diff --git a/attn/attn_common.cpp b/attn/attn_common.cpp
index d387b4f..d3bb6ba 100644
--- a/attn/attn_common.cpp
+++ b/attn/attn_common.cpp
@@ -157,4 +157,40 @@
     return recoverableErrors;
 }
 
+/** @brief timesec less-than-equal-to compare */
+bool operator<=(const timespec& lhs, const timespec& rhs)
+{
+    if (lhs.tv_sec == rhs.tv_sec)
+        return lhs.tv_nsec <= rhs.tv_nsec;
+    else
+        return lhs.tv_sec <= rhs.tv_sec;
+}
+
+/** @brief sleep for n-seconds */
+void sleepSeconds(const unsigned int seconds)
+{
+    auto count = seconds;
+    struct timespec requested, remaining;
+
+    while (0 < count)
+    {
+        requested.tv_sec  = 1;
+        requested.tv_nsec = 0;
+        remaining         = requested;
+
+        while (-1 == nanosleep(&requested, &remaining))
+        {
+            // if not changing or implausible then abort
+            if (requested <= remaining)
+            {
+                break;
+            }
+
+            // back to sleep
+            requested = remaining;
+        }
+        count--;
+    }
+}
+
 } // namespace attn
diff --git a/attn/attn_common.hpp b/attn/attn_common.hpp
index 938af36..ad93a0a 100644
--- a/attn/attn_common.hpp
+++ b/attn/attn_common.hpp
@@ -3,6 +3,9 @@
 namespace attn
 {
 
+// number of seconds to wait for power fault handling
+constexpr int POWER_FAULT_WAIT = 10;
+
 /** @brief Attention handler return codes */
 enum ReturnCodes
 {
@@ -52,4 +55,11 @@
  */
 bool recoverableErrors();
 
+/**
+ * @brief sleep for n-seconds
+ *
+ * @param[in] seconds number of seconds to sleep
+ */
+void sleepSeconds(const unsigned int seconds);
+
 } // namespace attn
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index 67390d8..4022d06 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -243,6 +243,9 @@
     }
     else
     {
+        // wait for power fault handling before starting analyses
+        sleepSeconds(POWER_FAULT_WAIT);
+
         // Look for any attentions found in hardware. This will generate and
         // commit a PEL if any errors are found.
         DumpParameters dumpParameters;