Skip to content

Commit

Permalink
new(userspace/libsinsp): support lxc 4.0 cgroup layout.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed May 29, 2024
1 parent 62a6399 commit 1d31ad6
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions userspace/libsinsp/container_engine/lxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,35 @@ limitations under the License.

using namespace libsinsp::container_engine;

constexpr const std::string_view LXC_CGROUP_LAYOUT[] = {
"/lxc/", // non-systemd
"/lxc.payload/", // systemd
"/lxc.payload.", // lxc4.0 layout: https://linuxcontainers.org/lxc/news/2020_03_25_13_03.html
};

bool lxc::resolve(sinsp_threadinfo *tinfo, bool query_os_for_missing_info)
{
auto container = sinsp_container_info();
bool matches = false;

for(const auto& it : tinfo->cgroups())
{
//
// Non-systemd LXC
//
const auto& cgroup = it.second;
size_t pos = cgroup.find("/lxc/");
if(pos != std::string::npos)
const auto &cgroup = it.second;
for(const auto &cgroup_layout : LXC_CGROUP_LAYOUT)
{
auto id_start = pos + sizeof("/lxc/") - 1;
auto id_end = cgroup.find('/', id_start);
container.m_type = CT_LXC;
container.m_id = cgroup.substr(id_start, id_end - id_start);
matches = true;
break;
size_t pos = cgroup.find(cgroup_layout);
if(pos != std::string::npos)
{
auto id_start = pos + cgroup_layout.length();
auto id_end = cgroup.find('/', id_start);
container.m_type = CT_LXC;
container.m_id = cgroup.substr(id_start, id_end - id_start);
matches = true;
break;
}
}

pos = cgroup.find("/lxc.payload/");
if(pos != std::string::npos)
if (matches)
{
auto id_start = pos + sizeof("/lxc.payload/") - 1;
auto id_end = cgroup.find('/', id_start);
container.m_type = CT_LXC;
container.m_id = cgroup.substr(id_start, id_end - id_start);
matches = true;
break;
}
}
Expand Down

0 comments on commit 1d31ad6

Please sign in to comment.