summaryrefslogtreecommitdiffstats
path: root/libutils/ProcessCallStack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libutils/ProcessCallStack.cpp')
-rw-r--r--libutils/ProcessCallStack.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index db07e56..39e7488 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -18,6 +18,7 @@
// #define LOG_NDEBUG 0
#include <string.h>
+#include <memory>
#include <stdio.h>
#include <dirent.h>
@@ -129,11 +130,9 @@ void ProcessCallStack::clear() {
}
void ProcessCallStack::update() {
- DIR *dp;
struct dirent *ep;
- struct dirent entry;
- dp = opendir(PATH_SELF_TASK);
+ std::unique_ptr<DIR, decltype(&closedir)> dp(opendir(PATH_SELF_TASK), closedir);
if (dp == NULL) {
ALOGE("%s: Failed to update the process's call stacks (errno = %d, '%s')",
__FUNCTION__, errno, strerror(errno));
@@ -158,8 +157,7 @@ void ProcessCallStack::update() {
* Each tid is a directory inside of /proc/self/task
* - Read every file in directory => get every tid
*/
- int code;
- while ((code = readdir_r(dp, &entry, &ep)) == 0 && ep != NULL) {
+ while ((ep = readdir(dp.get())) != NULL) {
pid_t tid = -1;
sscanf(ep->d_name, "%d", &tid);
@@ -194,13 +192,8 @@ void ProcessCallStack::update() {
ALOGV("%s: Got call stack for tid %d (size %zu)",
__FUNCTION__, tid, threadInfo.callStack.size());
}
- if (code != 0) { // returns positive error value on error
- ALOGE("%s: Failed to readdir from %s (errno = %d, '%s')",
- __FUNCTION__, PATH_SELF_TASK, -code, strerror(code));
- }
#endif
- closedir(dp);
}
void ProcessCallStack::log(const char* logtag, android_LogPriority priority,