diff --git a/userspace/libsinsp/container_engine/lxc.cpp b/userspace/libsinsp/container_engine/lxc.cpp index f217b7749d..ce161ad962 100644 --- a/userspace/libsinsp/container_engine/lxc.cpp +++ b/userspace/libsinsp/container_engine/lxc.cpp @@ -21,6 +21,12 @@ 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(); @@ -28,29 +34,22 @@ bool lxc::resolve(sinsp_threadinfo *tinfo, bool query_os_for_missing_info) 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; } } diff --git a/userspace/libsinsp/plugin.cpp b/userspace/libsinsp/plugin.cpp index d7f57b1a64..cadd90a642 100755 --- a/userspace/libsinsp/plugin.cpp +++ b/userspace/libsinsp/plugin.cpp @@ -19,6 +19,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -939,11 +940,7 @@ std::vector sinsp_plugin::get_metrics() const metrics_v2 metric; //copy plugin name - int s = strlcpy(metric.name, m_name.c_str(), METRIC_NAME_MAX); - //copy dot - strlcpy(metric.name + s, ".", METRIC_NAME_MAX); - //copy metric name - strlcpy(metric.name + s + 1, plugin_metric->name, METRIC_NAME_MAX); + snprintf(metric.name, METRIC_NAME_MAX, "%s.%s", m_name.c_str(), plugin_metric->name); metric.flags = METRICS_V2_PLUGINS; metric.unit = METRIC_VALUE_UNIT_COUNT; @@ -1083,7 +1080,7 @@ ss_plugin_rc sinsp_plugin::handle_plugin_async_event(ss_plugin_owner_t *o, const try { - auto evt = std::unique_ptr(new sinsp_evt()); + auto evt = std::make_unique(); ASSERT(evt->get_scap_evt_storage() == nullptr); evt->set_scap_evt_storage(new char[e->len]); memcpy(evt->get_scap_evt_storage(), e, e->len);