From 4e644c445fd461ca1444a0cafa075bdad2b4e4f2 Mon Sep 17 00:00:00 2001 From: Marco Ballesio Date: Wed, 24 Feb 2021 16:30:50 -0800 Subject: [PATCH] libprocessgroup: new method to get cgroup paths Bug: 180056337 Test: Verified the app freezer is correctly enabled via logs Change-Id: I3d954dd9bb0f1fa509a275d587e603f33a9d563f --- libprocessgroup/include/processgroup/processgroup.h | 7 ++++++- libprocessgroup/processgroup.cpp | 4 ++++ libprocessgroup/profiles/cgroups.json | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index 1aaed7bac..f826e9cf9 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -36,7 +36,8 @@ bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector& pr static constexpr const char* CGROUPS_RC_PATH = "/dev/cgroup_info/cgroup.rc"; // Path to test against for freezer support -// TODO: remove and replace with a function call, see http://b/180056337 +// TODO: remove it once https://r.android.com/1607196 is properly merged to all branches, +// see http://b/180056337 static constexpr const char* CGROUP_FREEZE_PATH = "/sys/fs/cgroup/uid_0/cgroup.freeze"; bool UsePerAppMemcg(); @@ -68,6 +69,10 @@ bool setProcessGroupLimit(uid_t uid, int initialPid, int64_t limitInBytes); void removeAllProcessGroups(void); +// Provides the path for an attribute in a specific process group +// Returns false in case of error, true in case of success +bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path); + #endif // __ANDROID_VNDK__ __END_DECLS diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 209ccd9fd..815d2bb78 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -508,3 +508,7 @@ bool setProcessGroupSoftLimit(uid_t, int pid, int64_t soft_limit_in_bytes) { bool setProcessGroupLimit(uid_t, int pid, int64_t limit_in_bytes) { return SetProcessGroupValue(pid, "MemLimit", limit_in_bytes); } + +bool getAttributePathForTask(const std::string& attr_name, int tid, std::string* path) { + return CgroupGetAttributePathForTask(attr_name, tid, path); +} diff --git a/libprocessgroup/profiles/cgroups.json b/libprocessgroup/profiles/cgroups.json index 7bcb94bd9..962d2baa8 100644 --- a/libprocessgroup/profiles/cgroups.json +++ b/libprocessgroup/profiles/cgroups.json @@ -37,7 +37,7 @@ "Controllers": [ { "Controller": "freezer", - "Path": "freezer", + "Path": ".", "Mode": "0755", "UID": "system", "GID": "system"