This is an automated email from the ASF dual-hosted git repository.
bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 25029f009 [cgroups2] Make cgroups2::path take both absolute and
relative paths.
25029f009 is described below
commit 25029f0095774f654293d13c3f0fb2b6e21cea16
Author: Jason Zhou <[email protected]>
AuthorDate: Thu Jul 11 15:08:34 2024 -0400
[cgroups2] Make cgroups2::path take both absolute and relative paths.
Currently, cgroups2::path assumes the path in the argument is relative.
We want the function to be able to distinguish between absolute and
relative paths, where we only prepend the mounting point on the
relative path.
Review: https://reviews.apache.org/r/75081/
---
src/linux/cgroups2.cpp | 4 +++-
src/tests/containerizer/cgroups2_tests.cpp | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index 31fee0459..faf3a5853 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -564,7 +564,9 @@ Try<set<pid_t>> threads(const string& cgroup)
string path(const string& cgroup)
{
- return path::join(cgroups2::MOUNT_POINT, cgroup);
+ return (!cgroup.empty() && cgroup.at(0) == '/')
+ ? cgroup
+ : path::join(cgroups2::MOUNT_POINT, cgroup);
}
namespace controllers {
diff --git a/src/tests/containerizer/cgroups2_tests.cpp
b/src/tests/containerizer/cgroups2_tests.cpp
index e4796b6ca..2ee39b342 100644
--- a/src/tests/containerizer/cgroups2_tests.cpp
+++ b/src/tests/containerizer/cgroups2_tests.cpp
@@ -129,6 +129,7 @@ TEST_F(Cgroups2Test, CGROUPS2_Path)
EXPECT_EQ("/sys/fs/cgroup/", cgroups2::path(cgroups2::ROOT_CGROUP));
EXPECT_EQ("/sys/fs/cgroup/foo", cgroups2::path("foo"));
EXPECT_EQ("/sys/fs/cgroup/foo/bar", cgroups2::path("foo/bar"));
+ EXPECT_EQ("/mount/cgroup/foo/bar", cgroups2::path("/mount/cgroup/foo/bar"));
}