summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libprocessgroup/processgroup.cpp10
-rw-r--r--libutils/ProcessCallStack.cpp13
2 files changed, 7 insertions, 16 deletions
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index ad0500d..0fa835b 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -164,9 +164,8 @@ static void removeUidProcessGroups(const char *uid_path)
{
DIR *uid = opendir(uid_path);
if (uid != NULL) {
- struct dirent cur;
- struct dirent *dir;
- while ((readdir_r(uid, &cur, &dir) == 0) && dir) {
+ dirent* dir;
+ while ((dir = readdir(uid.get())) != nullptr) {
char path[PROCESSGROUP_MAX_PATH_LEN];
if (dir->d_type != DT_DIR) {
@@ -192,9 +191,8 @@ void removeAllProcessGroups()
if (root == NULL) {
SLOGE("failed to open %s: %s", PROCESSGROUP_CGROUP_PATH, strerror(errno));
} else {
- struct dirent cur;
- struct dirent *dir;
- while ((readdir_r(root, &cur, &dir) == 0) && dir) {
+ dirent* dir;
+ while ((dir = readdir(root.get())) != nullptr) {
char path[PROCESSGROUP_MAX_PATH_LEN];
if (dir->d_type != DT_DIR) {
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,