Skip to content

Commit

Permalink
new(sinsp): allow custom host root in sinsp_cgroup
Browse files Browse the repository at this point in the history
Signed-off-by: Grzegorz Nosek <[email protected]>
  • Loading branch information
gnosek authored and poiana committed Jun 29, 2023
1 parent 741672d commit d2df713
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions userspace/libsinsp/sinsp_cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> sinsp_cgroup::lookup_cgroup_dir(const std::string &subsys, int &version)
Expand All @@ -51,7 +57,7 @@ std::shared_ptr<std::string> 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];

Expand Down
3 changes: 3 additions & 0 deletions userspace/libsinsp/sinsp_cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class sinsp_cgroup {
public:
sinsp_cgroup();

explicit sinsp_cgroup(std::string &&root);

virtual ~sinsp_cgroup();

std::shared_ptr<std::string> lookup_cgroup_dir(const std::string &subsys, int &version);
Expand All @@ -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<std::string, std::pair<std::shared_ptr<std::string>, int>> m_cgroup_dir_cache;
};

0 comments on commit d2df713

Please sign in to comment.