Remove hardcoded cgroup v2 path

Replace hardcoded cgroup v2 root path with new libprocessgroup API calls.

Bug: 111307099
Test: builds, boots

Change-Id: Ic9c47b52702767f9934f65d04bb91ab303b1d06e
Merged-In: Ic9c47b52702767f9934f65d04bb91ab303b1d06e
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
diff --git a/libbpf_android/BpfUtils.cpp b/libbpf_android/BpfUtils.cpp
index f5741bb..74585b2 100644
--- a/libbpf_android/BpfUtils.cpp
+++ b/libbpf_android/BpfUtils.cpp
@@ -38,6 +38,7 @@
 #include <log/log.h>
 #include <netdutils/MemBlock.h>
 #include <netdutils/Slice.h>
+#include <processgroup/processgroup.h>
 
 using android::base::GetUintProperty;
 using android::base::unique_fd;
@@ -272,7 +273,13 @@
         return ret;
     }
     if (prog->attachType == BPF_CGROUP_INET_EGRESS || prog->attachType == BPF_CGROUP_INET_INGRESS) {
-        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 ret;
+        }
+        unique_fd cg_fd(open(cg2_path.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC));
         if (cg_fd < 0) {
             int ret = -errno;
             ALOGE("Failed to open the cgroup directory");