Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(userspace/libsinsp): support lxc 4.0 cgroup layout. #1879

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading