diff --git a/userspace/libsinsp/sinsp_cgroup.cpp b/userspace/libsinsp/sinsp_cgroup.cpp index 000ad970b..bfd428ddf 100644 --- a/userspace/libsinsp/sinsp_cgroup.cpp +++ b/userspace/libsinsp/sinsp_cgroup.cpp @@ -21,10 +21,16 @@ limitations under the License. #include "sinsp.h" sinsp_cgroup::sinsp_cgroup() : + sinsp_cgroup(scap_get_host_root()) +{ +} + +sinsp_cgroup::sinsp_cgroup(std::string &&root) : + m_root(std::move(root)), m_scap_cgroup({}) { char error[SCAP_LASTERR_SIZE]; - scap_cgroup_interface_init(&m_scap_cgroup, error, false); + scap_cgroup_interface_init(&m_scap_cgroup, m_root.c_str(), error, false); } std::shared_ptr sinsp_cgroup::lookup_cgroup_dir(const std::string &subsys, int &version) @@ -51,7 +57,7 @@ std::shared_ptr sinsp_cgroup::lookup_cgroup_dir(const std::string & void sinsp_cgroup::lookup_cgroups(sinsp_threadinfo& tinfo) { - std::string procdirname = scap_get_host_root() + std::string("/proc/") + std::to_string(tinfo.m_tid); + std::string procdirname = m_root + "/proc/" + std::to_string(tinfo.m_tid) + '/'; struct scap_cgroup_set thread_cgroups = {}; char error[SCAP_LASTERR_SIZE]; diff --git a/userspace/libsinsp/sinsp_cgroup.h b/userspace/libsinsp/sinsp_cgroup.h index 368247e5b..58e11bd82 100644 --- a/userspace/libsinsp/sinsp_cgroup.h +++ b/userspace/libsinsp/sinsp_cgroup.h @@ -29,6 +29,8 @@ class sinsp_cgroup { public: sinsp_cgroup(); + explicit sinsp_cgroup(std::string &&root); + virtual ~sinsp_cgroup(); std::shared_ptr lookup_cgroup_dir(const std::string &subsys, int &version); @@ -38,6 +40,7 @@ class sinsp_cgroup { static sinsp_cgroup &instance(); protected: + std::string m_root; struct scap_cgroup_interface m_scap_cgroup; std::unordered_map, int>> m_cgroup_dir_cache; };