Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FedeDP/container_plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 76348e19f2b2c848748dad458aa7c084778210bf
Choose a base ref
..
head repository: FedeDP/container_plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3a55b0f9be6a5374ced10b5a060029c2a3384786
Choose a head ref
Showing with 9 additions and 6 deletions.
  1. +1 −1 src/matchers/containerd.cpp
  2. +6 −4 src/matchers/runc.cpp
  3. +2 −1 src/matchers/runc.h
2 changes: 1 addition & 1 deletion src/matchers/containerd.cpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ bool containerd::resolve(const std::string& cgroup, std::string& container_id) {
out << "/" << containerd_namespace << "/";
auto layout_str = out.str();
cgroup_layout CONTAINERD_CGROUP_LAYOUT[] = {{layout_str.c_str(), ""}, {nullptr, nullptr}};
return matches_runc_cgroup(cgroup, CONTAINERD_CGROUP_LAYOUT, container_id);
return matches_runc_cgroup(cgroup, CONTAINERD_CGROUP_LAYOUT, container_id, true);
}
return false;
}
10 changes: 6 additions & 4 deletions src/matchers/runc.cpp
Original file line number Diff line number Diff line change
@@ -23,7 +23,8 @@ inline static bool endswith(const std::string &s, const std::string &suffix) {
bool match_one_container_id(const std::string &cgroup,
const std::string &prefix,
const std::string &suffix,
std::string &container_id) {
std::string &container_id,
bool is_containerd) {
size_t start_pos = cgroup.rfind(prefix);
if(start_pos == std::string::npos) {
return false;
@@ -49,7 +50,7 @@ bool match_one_container_id(const std::string &cgroup,
}

// For containerd, make sure to skip systemd host cgroups
if(!endswith(cgroup, ".service") &&
if(is_containerd && !endswith(cgroup, ".service") &&
!endswith(cgroup, ".slice")) {
const size_t reported_len = end_pos - start_pos >= REPORTED_CONTAINER_ID_LENGTH
? REPORTED_CONTAINER_ID_LENGTH
@@ -63,9 +64,10 @@ bool match_one_container_id(const std::string &cgroup,

bool matches_runc_cgroup(const std::string &cgroup,
const libsinsp::runc::cgroup_layout *layout,
std::string &container_id) {
std::string &container_id,
bool is_containerd) {
for(size_t i = 0; layout[i].prefix && layout[i].suffix; ++i) {
if(match_one_container_id(cgroup, layout[i].prefix, layout[i].suffix, container_id)) {
if(match_one_container_id(cgroup, layout[i].prefix, layout[i].suffix, container_id, is_containerd)) {
return true;
}
}
3 changes: 2 additions & 1 deletion src/matchers/runc.h
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ bool match_one_container_id(const std::string &cgroup,
*/
bool matches_runc_cgroup(const std::string &cgroup,
const libsinsp::runc::cgroup_layout *layout,
std::string &container_id);
std::string &container_id,
bool is_containerd=false);
} // namespace runc
} // namespace libsinsp