diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp index 73d484ea297..8a0c34d86f2 100644 --- a/src/linux/cgroups2.cpp +++ b/src/linux/cgroups2.cpp @@ -243,6 +243,11 @@ Try unmount() } +bool exists(const string& cgroup) +{ + return os::exists(path::join(MOUNT_POINT, cgroup)); +} + Try create(const string& cgroup, bool recursive) { const string absolutePath = path::join(MOUNT_POINT, cgroup); @@ -259,12 +264,11 @@ Try create(const string& cgroup, bool recursive) Try destroy(const string& cgroup) { - const string absolutePath = path::join(MOUNT_POINT, cgroup); - - if (!os::exists(absolutePath)) { - return Error("There does not exist a cgroup at '" + absolutePath + "'"); + if (!cgroups2::exists(cgroup)) { + return Error("Cgroup '" + cgroup + "' does not exist"); } + const string absolutePath = path::join(MOUNT_POINT, cgroup); Try rmdir = os::rmdir(absolutePath, false); if (rmdir.isError()) { return Error("Failed to remove directory '" + absolutePath + "': " diff --git a/src/linux/cgroups2.hpp b/src/linux/cgroups2.hpp index 3f75e8e2be7..271c6ffbb9a 100644 --- a/src/linux/cgroups2.hpp +++ b/src/linux/cgroups2.hpp @@ -50,6 +50,9 @@ Try mounted(); Try unmount(); +// Check if a cgroup exists. +bool exists(const std::string& cgroup); + // Creates a cgroup off of the base hierarchy, i.e. /sys/fs/cgroup/. // cgroup can be a nested cgroup (e.g. foo/bar/baz). If cgroup is a nested // cgroup and the parent cgroups do not exist, an error will be returned unless