summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-09-28 13:29:54 -0700
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2016-12-09 04:59:43 +0100
commit821ba553140387c31998977cbb490f3c7b96eadc (patch)
tree8cfb51c81ff37806fc69acc52cc55341aba3a268
parent7f2bb91aecbdc8af268c56f80034d8f3dc0204aa (diff)
downloadsystem_core-821ba553140387c31998977cbb490f3c7b96eadc.zip
system_core-821ba553140387c31998977cbb490f3c7b96eadc.tar.gz
system_core-821ba553140387c31998977cbb490f3c7b96eadc.tar.bz2
Use readdir instead of readdir_r.
http://elliotth.blogspot.com/2012/10/how-not-to-use-readdirr3.html Test: boots. Change-Id: If75532e24fe4d17743bf8e8c9590156dee378a63
-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,