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

refactor: bump libs and driver, and adopt unique pointers wherever possible #3109

Merged
merged 6 commits into from
Feb 23, 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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
option(BUILD_FALCO_UNIT_TESTS "Build falco unit tests" OFF)

if(WIN32)
if(POLICY CMP0091)
# Needed for CMAKE_MSVC_RUNTIME_LIBRARY
# https://cmake.org/cmake/help/latest/policy/CMP0091.html
cmake_policy(SET CMP0091 NEW)
endif()
set(CPACK_GENERATOR "NSIS") # this needs NSIS installed, and available
elseif (APPLE)
set(CPACK_GENERATOR "DragNDrop")
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ if(NOT MSVC)

else() # MSVC
set(MINIMAL_BUILD ON)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# The WIN32_LEAN_AND_MEAN define avoids possible macro pollution
# when a libsinsp consumer includes the windows.h header.
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/driver.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ else()
# In case you want to test against another driver version (or branch, or commit) just pass the variable -
# ie., `cmake -DDRIVER_VERSION=dev ..`
if(NOT DRIVER_VERSION)
set(DRIVER_VERSION "93a04bb92f85142edbfb47120cbaafb45d9ba5d8")
set(DRIVER_CHECKSUM "SHA256=8df88170cfcdd617366ef470bca9ac29be22cff36cafdac74a288697d5c860ab")
set(DRIVER_VERSION "f2eabad40d2b3bd74c63743ed7f7a020c85f3aaa")
set(DRIVER_CHECKSUM "SHA256=5e1d0d6ff736b49b8b49e9cf5881be8db622cea5586d71d1974b6f8152e0b978")
endif()

# cd /path/to/build && cmake /path/to/source
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/falcosecurity-libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ else()
# In case you want to test against another falcosecurity/libs version (or branch, or commit) just pass the variable -
# ie., `cmake -DFALCOSECURITY_LIBS_VERSION=dev ..`
if(NOT FALCOSECURITY_LIBS_VERSION)
set(FALCOSECURITY_LIBS_VERSION "93a04bb92f85142edbfb47120cbaafb45d9ba5d8")
set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=8df88170cfcdd617366ef470bca9ac29be22cff36cafdac74a288697d5c860ab")
set(FALCOSECURITY_LIBS_VERSION "f2eabad40d2b3bd74c63743ed7f7a020c85f3aaa")
set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=5e1d0d6ff736b49b8b49e9cf5881be8db622cea5586d71d1974b6f8152e0b978")
endif()

# cd /path/to/build && cmake /path/to/source
Expand Down
4 changes: 2 additions & 2 deletions userspace/engine/falco_engine_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

// The version of this Falco engine
#define FALCO_ENGINE_VERSION_MAJOR 0
#define FALCO_ENGINE_VERSION_MINOR 34
#define FALCO_ENGINE_VERSION_MINOR 35
#define FALCO_ENGINE_VERSION_PATCH 0

#define FALCO_ENGINE_VERSION \
Expand All @@ -34,4 +34,4 @@ limitations under the License.
// It represents the fields supported by this version of Falco,
// the event types, and the underlying driverevent schema. It's used to
// detetect changes in engine version in our CI jobs.
#define FALCO_ENGINE_CHECKSUM "8c1ad46ec49050af497561f732915f01adc699c6beed5139a7e6520a8196ca7d"
#define FALCO_ENGINE_CHECKSUM "8b7007b6fdef6abc6661ccfb4424052e7c4838d59f7be3ae31ab1e7b10223c93"
4 changes: 1 addition & 3 deletions userspace/engine/falco_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ struct falco_source

inline bool is_field_defined(const std::string& field) const
{
auto *chk = filter_factory->new_filtercheck(field.c_str());
if (chk)
if (filter_factory->new_filtercheck(field.c_str()) != nullptr)
{
delete(chk);
return true;
}
return false;
Expand Down
17 changes: 0 additions & 17 deletions userspace/engine/filter_macro_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

using namespace libsinsp::filter;

bool filter_macro_resolver::run(libsinsp::filter::ast::expr*& filter)
{
m_unknown_macros.clear();
m_resolved_macros.clear();
m_errors.clear();

visitor v(m_errors, m_unknown_macros, m_resolved_macros, m_macros);
v.m_node_substitute = nullptr;
filter->accept(&v);
if (v.m_node_substitute)
{
delete filter;
filter = v.m_node_substitute.release();
}
return !m_resolved_macros.empty();
}

bool filter_macro_resolver::run(std::shared_ptr<libsinsp::filter::ast::expr>& filter)
{
m_unknown_macros.clear();
Expand Down
5 changes: 0 additions & 5 deletions userspace/engine/filter_macro_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class filter_macro_resolver
class and is deleted automatically.
\return true if at least one of the defined macros is resolved
*/
bool run(libsinsp::filter::ast::expr*& filter);

/*!
\brief Version of run() that works with shared pointers
*/
bool run(std::shared_ptr<libsinsp::filter::ast::expr>& filter);

/*!
Expand Down
2 changes: 1 addition & 1 deletion userspace/engine/rule_loader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ bool rule_loader::compiler::compile_condition(
sinsp_filter_compiler compiler(filter_factory, ast_out.get());
try
{
filter_out.reset(compiler.compile());
filter_out = std::move(compiler.compile());
}
catch(const sinsp_exception& e)
{
Expand Down
2 changes: 1 addition & 1 deletion userspace/falco/app/actions/init_inspectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ falco::app::run_result falco::app::actions::init_inspectors(falco::app::state& s
if (is_input)
{
auto gen_check = src_info->inspector->new_generic_filtercheck();
src_info->filterchecks->add_filter_check(gen_check);
src_info->filterchecks->add_filter_check(std::move(gen_check));
}
used_plugins.insert(plugin->name());
}
Expand Down
29 changes: 12 additions & 17 deletions userspace/falco/falco_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,45 +77,41 @@ falco_outputs::~falco_outputs()
#ifndef __EMSCRIPTEN__
this->stop_worker();
#endif
for(auto o : m_outputs)
{
delete o;
}
}

// This function is called only at initialization-time by the constructor
void falco_outputs::add_output(const falco::outputs::config &oc)
{
falco::outputs::abstract_output *oo;
std::unique_ptr<falco::outputs::abstract_output> oo;

if(oc.name == "file")
{
oo = new falco::outputs::output_file();
oo = std::make_unique<falco::outputs::output_file>();
}
#ifndef _WIN32
else if(oc.name == "program")
{
oo = new falco::outputs::output_program();
oo = std::make_unique<falco::outputs::output_program>();
}
#endif
else if(oc.name == "stdout")
{
oo = new falco::outputs::output_stdout();
oo = std::make_unique<falco::outputs::output_stdout>();
}
#ifndef _WIN32
else if(oc.name == "syslog")
{
oo = new falco::outputs::output_syslog();
oo = std::make_unique<falco::outputs::output_syslog>();
}
#endif
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(MINIMAL_BUILD)
else if(oc.name == "http")
{
oo = new falco::outputs::output_http();
oo = std::make_unique<falco::outputs::output_http>();
}
else if(oc.name == "grpc")
{
oo = new falco::outputs::output_grpc();
oo = std::make_unique<falco::outputs::output_grpc>();
}
#endif
else
Expand All @@ -126,12 +122,11 @@ void falco_outputs::add_output(const falco::outputs::config &oc)
std::string init_err;
if (oo->init(oc, m_buffered, m_hostname, m_json_output, init_err))
{
m_outputs.push_back(oo);
m_outputs.push_back(std::move(oo));
}
else
{
falco_logger::log(falco_logger::level::ERR, "Failed to init output: " + init_err);
delete(oo);
}
}

Expand Down Expand Up @@ -296,9 +291,9 @@ inline void falco_outputs::push(const ctrl_msg& cmsg)
m_outputs_queue_num_drops++;
}
#else
for (auto o : m_outputs)
for (const auto& o : m_outputs)
{
process_msg(o, cmsg);
process_msg(o.get(), cmsg);
}
#endif
}
Expand All @@ -323,12 +318,12 @@ void falco_outputs::worker() noexcept
m_queue.pop(cmsg);
#endif

for(auto o : m_outputs)
for(const auto& o : m_outputs)
{
wd.set_timeout(timeout, o->get_name());
try
{
process_msg(o, cmsg);
process_msg(o.get(), cmsg);
}
catch(const std::exception &e)
{
Expand Down
2 changes: 1 addition & 1 deletion userspace/falco/falco_outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class falco_outputs
private:
std::unique_ptr<falco_formats> m_formats;

std::vector<falco::outputs::abstract_output *> m_outputs;
std::vector<std::unique_ptr<falco::outputs::abstract_output>> m_outputs;

bool m_buffered;
bool m_json_output;
Expand Down
2 changes: 1 addition & 1 deletion userspace/falco/stats_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void stats_writer::collector::get_metrics_output_fields_additional(

auto buffer = inspector->get_sinsp_stats_v2_buffer();
auto sinsp_stats_v2 = inspector->get_sinsp_stats_v2();
sinsp_thread_manager* thread_manager = inspector->m_thread_manager;
sinsp_thread_manager* thread_manager = inspector->m_thread_manager.get();
const scap_stats_v2* sinsp_stats_v2_snapshot = libsinsp::stats::get_sinsp_stats_v2(flags, agent_info, thread_manager, sinsp_stats_v2, buffer, &nstats, &rc);

uint32_t base_stat = 0;
Expand Down
14 changes: 6 additions & 8 deletions userspace/falco/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ void falco_webserver::start(
// allocate and configure server
if (ssl_enabled)
{
m_server = new httplib::SSLServer(
m_server = std::make_unique<httplib::SSLServer>(
ssl_certificate.c_str(),
ssl_certificate.c_str());
}
else
{
m_server = new httplib::Server();
m_server = std::make_unique<httplib::Server>();
}

// configure server
Expand All @@ -71,8 +71,7 @@ void falco_webserver::start(
// run server in a separate thread
if (!m_server->is_valid())
{
delete m_server;
m_server = NULL;
m_server = nullptr;
throw falco_exception("invalid webserver configuration");
}

Expand Down Expand Up @@ -111,18 +110,17 @@ void falco_webserver::stop()
{
if (m_running)
{
if (m_server != NULL)
if (m_server != nullptr)
{
m_server->stop();
}
if(m_server_thread.joinable())
{
m_server_thread.join();
}
if (m_server != NULL)
if (m_server != nullptr)
{
delete m_server;
m_server = NULL;
m_server = nullptr;
}
m_running = false;
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/falco/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ class falco_webserver

private:
bool m_running = false;
httplib::Server* m_server = NULL;
std::unique_ptr<httplib::Server> m_server = nullptr;
std::thread m_server_thread;
};
Loading