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

sync: release 0.17.1 #1881

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 3 additions & 6 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

#include <inttypes.h>
#include <string.h>
#include <memory>
#include <vector>
#include <set>
#include <sstream>
Expand Down Expand Up @@ -939,11 +940,7 @@ std::vector<metrics_v2> 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;
Expand Down Expand Up @@ -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<sinsp_evt>(new sinsp_evt());
auto evt = std::make_unique<sinsp_evt>();
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);
Expand Down
Loading