summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adb/adb.cpp6
-rw-r--r--adb/commandline.cpp6
-rw-r--r--adb/sysdeps.h4
-rw-r--r--libprocessgroup/processgroup.cpp35
-rw-r--r--libutils/ProcessCallStack.cpp13
5 files changed, 36 insertions, 28 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp
index c09aee3..9f9e6bd 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -726,15 +726,15 @@ int handle_forward_request(const char* service, transport_type ttype, char* seri
int createForward = strncmp(service, "kill", 4);
int no_rebind = 0;
- local = strchr(service, ':') + 1;
+ local = (char*) strchr(service, ':') + 1;
// Handle forward:norebind:<local>... here
if (createForward && !strncmp(local, "norebind:", 9)) {
no_rebind = 1;
- local = strchr(local, ':') + 1;
+ local = (char*) strchr(local, ':') + 1;
}
- remote = strchr(local,';');
+ remote = (char*) strchr(local,';');
if (createForward) {
// Check forward: parameter format: '<local>;<remote>'
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 26eea2f..eb0c84b 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -463,7 +463,7 @@ static int adb_download_buffer(const char *service, const char *fn, const void*
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(data);
if (show_progress) {
- char *x = strrchr(service, ':');
+ char *x = (char*) strrchr(service, ':');
if(x) service = x + 1;
}
@@ -1571,7 +1571,7 @@ static int install_app(transport_type transport, const char* serial, int argc,
int last_apk = -1;
for (i = argc - 1; i >= 0; i--) {
const char* file = argv[i];
- char* dot = strrchr(file, '.');
+ char* dot = (char*) strrchr(file, '.');
if (dot && !strcasecmp(dot, ".apk")) {
if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
fprintf(stderr, "Invalid APK file: %s\n", file);
@@ -1617,7 +1617,7 @@ static int install_multiple_app(transport_type transport, const char* serial, in
int first_apk = -1;
for (i = argc - 1; i >= 0; i--) {
const char* file = argv[i];
- char* dot = strrchr(file, '.');
+ char* dot = (char*) strrchr(file, '.');
if (dot && !strcasecmp(dot, ".apk")) {
if (stat(file, &sb) == -1 || !S_ISREG(sb.st_mode)) {
fprintf(stderr, "Invalid APK file: %s\n", file);
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 59e5b0b..3550a44 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -502,12 +502,12 @@ static __inline__ void adb_sysdeps_init(void)
static __inline__ char* adb_dirstart(const char* path)
{
- return strchr(path, '/');
+ return (char*) strrchr(path, '/');
}
static __inline__ char* adb_dirstop(const char* path)
{
- return strrchr(path, '/');
+ return (char*) strrchr(path, '/');
}
static __inline__ int adb_is_absolute_host_path( const char* path )
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index ad0500d..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,11 +180,10 @@ 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) {
- 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) {
@@ -181,20 +198,19 @@ 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 {
- 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) {
@@ -209,7 +225,6 @@ void removeAllProcessGroups()
SLOGV("removing %s\n", path);
rmdir(path);
}
- closedir(root);
}
}
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,