Skip to content

Commit 33507ac

Browse files
committed
chore(plugins/container): introduce and use container_info::ptr_t
Signed-off-by: Angelo Puglisi <angelopuglisi86@gmail.com>
1 parent ec56a14 commit 33507ac

File tree

19 files changed

+27
-31
lines changed

19 files changed

+27
-31
lines changed

plugins/container/src/caps/async/async.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void generate_async_event(const char *json, bool added, bool initial_state)
4242
// we need pre-existing containers to be already cached.
4343
if (initial_state) {
4444
auto json_event = nlohmann::json::parse(json);
45-
auto cinfo = json_event.get<std::shared_ptr<container_info>>();
45+
auto cinfo = json_event.get<container_info::ptr_t>();
4646
s_preexisting_containers[cinfo->m_id] = cinfo;
4747
}
4848
}

plugins/container/src/caps/parse/parse.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool my_plugin::parse_async_event(const falcosecurity::parse_event_input& in)
7373
return false;
7474
}
7575
auto json_event = nlohmann::json::parse(json_charbuf_pointer);
76-
auto cinfo = json_event.get<std::shared_ptr<container_info>>();
76+
auto cinfo = json_event.get<container_info::ptr_t>();
7777
if(added)
7878
{
7979
m_logger.log(fmt::format("Adding container: {}", cinfo->m_id),
@@ -137,7 +137,7 @@ bool my_plugin::parse_container_json_event(
137137
std::string json_str = (char*)json_param.param_pointer;
138138
auto json_event = nlohmann::json::parse(json_str);
139139

140-
auto cinfo = json_event.get<std::shared_ptr<container_info>>();
140+
auto cinfo = json_event.get<container_info::ptr_t>();
141141
m_logger.log(
142142
fmt::format("Adding container from old container_json event: {}",
143143
cinfo->m_id),
@@ -156,7 +156,7 @@ bool my_plugin::parse_container_json_2_event(
156156
std::string json_str = (char*)json_param.param_pointer;
157157
auto json_event = nlohmann::json::parse(json_str);
158158

159-
auto cinfo = json_event.get<std::shared_ptr<container_info>>();
159+
auto cinfo = json_event.get<container_info::ptr_t>();
160160
m_logger.log(
161161
fmt::format("Adding container from old container_json_2 event: {}",
162162
cinfo->m_id),

plugins/container/src/container_info.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class container_health_probe
8686
class container_info
8787
{
8888
public:
89+
using ptr_t = std::shared_ptr<container_info>;
90+
8991
container_info():
9092
m_type(CT_UNKNOWN), m_privileged(false), m_host_pid(false),
9193
m_host_network(false), m_host_ipc(false), m_memory_limit(0),
@@ -104,7 +106,7 @@ class container_info
104106
bool is_pod_sandbox() const { return m_is_pod_sandbox; }
105107

106108
// static utilities to build a container_info
107-
static std::shared_ptr<container_info> host_container_info()
109+
static container_info::ptr_t host_container_info()
108110
{
109111
auto host_info = std::make_shared<container_info>();
110112
host_info->m_id = HOST_CONTAINER_ID;

plugins/container/src/container_info_json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ void from_json(const nlohmann::json& j, container_port_mapping& port)
8787
port.m_container_port = j.value("ContainerPort", 0);
8888
}
8989

90-
void from_json(const nlohmann::json& j, std::shared_ptr<container_info>& cinfo)
90+
void from_json(const nlohmann::json& j, container_info::ptr_t& cinfo)
9191
{
92-
std::shared_ptr<container_info> info = std::make_shared<container_info>();
92+
container_info::ptr_t info = std::make_shared<container_info>();
9393
const nlohmann::json& container = j["container"];
9494
info->m_type = container.value("type", CT_UNKNOWN);
9595
info->m_id = container.value("id", "");

plugins/container/src/container_info_json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
void from_json(const nlohmann::json& j, container_health_probe& probe);
88
void from_json(const nlohmann::json& j, container_mount_info& mount);
99
void from_json(const nlohmann::json& j, container_port_mapping& port);
10-
void from_json(const nlohmann::json& j, std::shared_ptr<container_info>& cinfo);
10+
void from_json(const nlohmann::json& j, container_info::ptr_t& cinfo);
1111

1212
void to_json(nlohmann::json& j, const container_health_probe& probe);
1313
void to_json(nlohmann::json& j, const container_mount_info& mount);

plugins/container/src/matchers/bpm.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ bool bpm::resolve(const std::string& cgroup, std::string& container_id)
2727
return false;
2828
}
2929

30-
std::shared_ptr<container_info>
31-
bpm::to_container(const std::string& container_id)
30+
container_info::ptr_t bpm::to_container(const std::string& container_id)
3231
{
3332
auto ctr = std::make_shared<container_info>();
3433
ctr->m_id = container_id;

plugins/container/src/matchers/bpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
class bpm : public cgroup_matcher
66
{
77
bool resolve(const std::string& cgroup, std::string& container_id) override;
8-
std::shared_ptr<container_info>
8+
container_info::ptr_t
99
to_container(const std::string& container_id) override;
1010
};

plugins/container/src/matchers/libvirt_lxc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ bool libvirt_lxc::resolve(const std::string& cgroup, std::string& container_id)
5252
return false;
5353
}
5454

55-
std::shared_ptr<container_info>
56-
libvirt_lxc::to_container(const std::string& container_id)
55+
container_info::ptr_t libvirt_lxc::to_container(const std::string& container_id)
5756
{
5857
auto ctr = std::make_shared<container_info>();
5958
ctr->m_id = container_id;

plugins/container/src/matchers/libvirt_lxc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
class libvirt_lxc : public cgroup_matcher
66
{
77
bool resolve(const std::string& cgroup, std::string& container_id) override;
8-
std::shared_ptr<container_info>
8+
container_info::ptr_t
99
to_container(const std::string& container_id) override;
1010
};

plugins/container/src/matchers/lxc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ bool lxc::resolve(const std::string& cgroup, std::string& container_id)
2323
return false;
2424
}
2525

26-
std::shared_ptr<container_info>
27-
lxc::to_container(const std::string& container_id)
26+
container_info::ptr_t lxc::to_container(const std::string& container_id)
2827
{
2928
auto ctr = std::make_shared<container_info>();
3029
ctr->m_id = container_id;

0 commit comments

Comments
 (0)