summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2016-12-09 22:33:58 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2016-12-09 22:33:58 +0100
commit870d7cfb19f49ced89117b403972eef4a05faf08 (patch)
tree90975a009b7a9d47e453af4a3a9741487b9a9d89
parent821ba553140387c31998977cbb490f3c7b96eadc (diff)
downloadsystem_core-870d7cfb19f49ced89117b403972eef4a05faf08.zip
system_core-870d7cfb19f49ced89117b403972eef4a05faf08.tar.gz
system_core-870d7cfb19f49ced89117b403972eef4a05faf08.tar.bz2
Fix backport of readdir patch
Backport changes from Google's master to fix build errors when using readdir_r. Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
-rw-r--r--libprocessgroup/processgroup.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 0fa835b..2ac73b1 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <log/log.h>
+#include <memory>
#include <private/android_filesystem_config.h>
#include <utils/SystemClock.h>
@@ -37,6 +38,8 @@
#include <processgroup/processgroup.h>
#include "processgroup_priv.h"
+#define ACCT_CGROUP_PATH "/acct"
+
struct ctx {
bool initialized;
int fd;
@@ -45,6 +48,21 @@ struct ctx {
size_t buf_len;
};
+static const char* getCgroupRootPath() {
+#ifdef USE_MEMCG
+ static const char* cgroup_root_path = NULL;
+ std::call_once(init_path_flag, [&]() {
+ // Check if mem cgroup is mounted, only then check for write-access to avoid
+ // SELinux denials
+ cgroup_root_path = access(MEM_CGROUP_TASKS, F_OK) || access(MEM_CGROUP_PATH, W_OK) ?
+ ACCT_CGROUP_PATH : MEM_CGROUP_PATH;
+ });
+ return cgroup_root_path;
+#else
+ return ACCT_CGROUP_PATH;
+#endif
+}
+
static int convertUidToPath(char *path, size_t size, uid_t uid)
{
return snprintf(path, size, "%s/%s%d",
@@ -162,7 +180,7 @@ static int removeProcessGroup(uid_t uid, int pid)
static void removeUidProcessGroups(const char *uid_path)
{
- DIR *uid = opendir(uid_path);
+ std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path), closedir);
if (uid != NULL) {
dirent* dir;
while ((dir = readdir(uid.get())) != nullptr) {
@@ -180,14 +198,14 @@ static void removeUidProcessGroups(const char *uid_path)
SLOGV("removing %s\n", path);
rmdir(path);
}
- closedir(uid);
}
}
void removeAllProcessGroups()
{
SLOGV("removeAllProcessGroups()");
- DIR *root = opendir(PROCESSGROUP_CGROUP_PATH);
+ const char* cgroup_root_path = getCgroupRootPath();
+ std::unique_ptr<DIR, decltype(&closedir)> root(opendir(cgroup_root_path), closedir);
if (root == NULL) {
SLOGE("failed to open %s: %s", PROCESSGROUP_CGROUP_PATH, strerror(errno));
} else {
@@ -207,7 +225,6 @@ void removeAllProcessGroups()
SLOGV("removing %s\n", path);
rmdir(path);
}
- closedir(root);
}
}