Remove hardcoded cgroup v2 path
Replace hardcoded cgroup v2 root path with new libprocessgroup API calls.
Bug: 111307099
Test: adb shell dumpsys netd trafficcontroller
Change-Id: I833f42410508ddb6ed7f50cd2ff5e26b3dedc4a8
Merged-In: I833f42410508ddb6ed7f50cd2ff5e26b3dedc4a8
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
diff --git a/server/TrafficController.cpp b/server/TrafficController.cpp
index b55e667..12cec42 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -43,6 +43,7 @@
#include <netdutils/Misc.h>
#include <netdutils/Syscalls.h>
+#include <processgroup/processgroup.h>
#include "TrafficController.h"
#include "bpf/BpfMap.h"
@@ -229,7 +230,15 @@
}
static Status initPrograms() {
- unique_fd cg_fd(open(CGROUP_ROOT_PATH, O_DIRECTORY | O_RDONLY | O_CLOEXEC));
+ std::string cg2_path;
+
+ if (!CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &cg2_path)) {
+ int ret = errno;
+ ALOGE("Failed to find cgroup v2 root");
+ return statusFromErrno(ret, "Failed to find cgroup v2 root");
+ }
+
+ unique_fd cg_fd(open(cg2_path.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC));
if (cg_fd == -1) {
int ret = errno;
ALOGE("Failed to open the cgroup directory: %s", strerror(ret));