Fix ignoring ENOENT 04/230204/6
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Wed, 8 Apr 2020 10:55:23 +0000 (12:55 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Fri, 10 Apr 2020 09:23:56 +0000 (09:23 +0000)
Also better error logging for check-proper-drop

Change-Id: I42bfff586d3a5d14a39ffbe16a8dfddea720d085

src/client/check-proper-drop.cpp

index 23fb1367ed4b0a3735f5757c5c28f7bab1fb6c3c..9deac7e3a8f7f7edaa7f6e69f4bd825b4b66e749 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <memory>
 #include <string>
+#include <cstring>
 
 namespace {
 
@@ -63,6 +64,7 @@ proc_t* readtask_priv(PROCTAB * const PT, const proc_t * const p)
         ret = PT->taskreader(PT,p,t,path);
         if (errno && errno != ENOENT)
             goto out;
+        errno = 0;
         if (ret != NULL)
             return ret;
     }
@@ -93,7 +95,7 @@ bool CheckProperDrop::getThreads()
     m_proc = readproc(proctabPtr.get(), nullptr);
     if (!m_proc)
         ThrowMsg(Exception::ProcError,
-            "Unable to read process information for " << pid);
+            "Unable to read process information for " << m_pid);
 
     proc_t *thread;
     while ((thread = readtask_priv(proctabPtr.get(), m_proc))) {
@@ -104,12 +106,17 @@ bool CheckProperDrop::getThreads()
     }
     if (errno == EACCES) {
         LogError("Permission denied while reading proc data, some threads might not be "
-                 "synchronized for " << pid);
+                 "synchronized for " << m_pid);
         return false;
     }
-    if (errno)
+    if (errno) {
+        static const unsigned ERROR_MSG_LEN = 1024;
+        char error_msg[ERROR_MSG_LEN];
+        const char *e = strerror_r(errno, error_msg, ERROR_MSG_LEN);
+
         ThrowMsg(Exception::ProcError,
-            "Unable to read process information for " << pid);
+            "Unable to read process information for " << m_pid << ": " << e);
+    }
 
     LogDebug("Reading proc data for " << m_threads.size() << " additional threads beside main thread");
     return true;