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

Cleanup warnings and smart ptrs #3112

Merged
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
3 changes: 1 addition & 2 deletions userspace/engine/evttype_index_ruleset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ void evttype_index_ruleset::clear()
{
for (size_t i = 0; i < m_rulesets.size(); i++)
{
std::shared_ptr<ruleset_filters> r(new ruleset_filters());
m_rulesets[i] = r;
m_rulesets[i] = std::make_shared<ruleset_filters>();
}
m_filters.clear();
}
Expand Down
8 changes: 3 additions & 5 deletions userspace/engine/evttype_index_ruleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class evttype_index_ruleset: public filter_ruleset
// that matched.
bool run(sinsp_evt *evt, falco_rule& match);

// Evaluate an event against the ruleset and return all the
// matching rules.
// Evaluate an event against the ruleset and return all the
// matching rules.
bool run(sinsp_evt *evt, std::vector<falco_rule>& matches);

libsinsp::events::set<ppm_sc_code> sc_codes();
Expand Down Expand Up @@ -164,9 +164,7 @@ class evttype_index_ruleset_factory: public filter_ruleset_factory

inline std::shared_ptr<filter_ruleset> new_ruleset() override
{
std::shared_ptr<filter_ruleset> ret(
new evttype_index_ruleset(m_filter_factory));
return ret;
return std::make_shared<evttype_index_ruleset>(m_filter_factory);
}

private:
Expand Down
5 changes: 2 additions & 3 deletions userspace/engine/falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,8 @@ std::size_t falco_engine::add_source(const std::string &source,
std::shared_ptr<sinsp_evt_formatter_factory> formatter_factory)
{
// evttype_index_ruleset is the default ruleset implementation
std::shared_ptr<filter_ruleset_factory> ruleset_factory(
new evttype_index_ruleset_factory(filter_factory));
size_t idx = add_source(source, filter_factory, formatter_factory, ruleset_factory);
size_t idx = add_source(source, filter_factory, formatter_factory,
std::make_shared<evttype_index_ruleset_factory>(filter_factory));

if(source == falco_common::syscall_source)
{
Expand Down
9 changes: 6 additions & 3 deletions userspace/engine/falco_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ See the License for the specific language governing permissions and
limitations under the License.

*/
#include <cstring>
#include <iomanip>

#include "falco_utils.h"
#include <libsinsp/utils.h>

#include <re2/re2.h>

#include <cstring>
#include <fstream>
#include <iomanip>
#include <thread>

#define RGX_PROMETHEUS_TIME_DURATION "^((?P<y>[0-9]+)y)?((?P<w>[0-9]+)w)?((?P<d>[0-9]+)d)?((?P<h>[0-9]+)h)?((?P<m>[0-9]+)m)?((?P<s>[0-9]+)s)?((?P<ms>[0-9]+)ms)?$"

// using pre-compiled regex
Expand Down Expand Up @@ -145,7 +148,7 @@ uint32_t hardware_concurrency()

void readfile(const std::string& filename, std::string& data)
{
std::ifstream file(filename.c_str(), std::ios::in);
std::ifstream file(filename, std::ios::in);

if(file.is_open())
{
Expand Down
26 changes: 3 additions & 23 deletions userspace/engine/falco_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,11 @@ limitations under the License.

#pragma once

#include <sstream>
#include <fstream>
#include <iostream>
#include <cstdint>
#include <string>
#include <thread>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>

#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (x)
#define unlikely(x) (x)
#endif

namespace falco
namespace falco::utils
{

namespace utils
{

uint64_t parse_prometheus_interval(std::string interval_str);

std::string wrap_text(const std::string& in, uint32_t indent, uint32_t linelen);
Expand All @@ -57,5 +38,4 @@ namespace network
static const std::string UNIX_SCHEME("unix://");
bool is_unix_scheme(const std::string& url);
} // namespace network
} // namespace utils
} // namespace falco
} // namespace falco::utils
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 = std::move(compiler.compile());
filter_out = compiler.compile();
}
catch(const sinsp_exception& e)
{
Expand Down
8 changes: 3 additions & 5 deletions userspace/falco/app/actions/init_falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ void configure_output_format(falco::app::state& s)
void add_source_to_engine(falco::app::state& s, const std::string& src)
{
auto src_info = s.source_infos.at(src);
auto& filterchecks = *src_info->filterchecks.get();
auto& filterchecks = *src_info->filterchecks;
auto* inspector = src_info->inspector.get();

auto filter_factory = std::shared_ptr<sinsp_filter_factory>(
new sinsp_filter_factory(inspector, filterchecks));
auto formatter_factory = std::shared_ptr<sinsp_evt_formatter_factory>(
new sinsp_evt_formatter_factory(inspector, filterchecks));
auto filter_factory = std::make_shared<sinsp_filter_factory>(inspector, filterchecks);
auto formatter_factory = std::make_shared<sinsp_evt_formatter_factory>(inspector, filterchecks);

if(s.config->m_json_output)
{
Expand Down
4 changes: 2 additions & 2 deletions userspace/falco/app/actions/list_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ falco::app::run_result falco::app::actions::list_plugins(const falco::app::state
if(s.options.list_plugins)
{
std::ostringstream os;
std::unique_ptr<sinsp> inspector(new sinsp());
sinsp inspector;
const auto& configs = s.config->m_plugins;
for (auto &c : configs)
{
// load the plugin (no need to initialize it)
auto plugin = inspector->register_plugin(c.m_library_path);
auto plugin = inspector.register_plugin(c.m_library_path);
format_plugin_info(plugin, os);
os << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions userspace/falco/app/actions/print_generated_gvisor_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ falco::app::run_result falco::app::actions::print_generated_gvisor_config(falco:
{
if(!s.options.gvisor_generate_config_with_socket.empty())
{
std::unique_ptr<sinsp> i(new sinsp());
std::string gvisor_config = i->generate_gvisor_config(s.options.gvisor_generate_config_with_socket);
sinsp i;
std::string gvisor_config = i.generate_gvisor_config(s.options.gvisor_generate_config_with_socket);
printf("%s\n", gvisor_config.c_str());
return run_result::exit();
}
Expand Down
6 changes: 3 additions & 3 deletions userspace/falco/app/actions/print_plugin_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ falco::app::run_result falco::app::actions::print_plugin_info(const falco::app::
{
if(!s.options.print_plugin_info.empty())
{
std::unique_ptr<sinsp> inspector(new sinsp());
sinsp inspector;
for(auto &pc : s.config->m_plugins)
{
if (pc.m_name == s.options.print_plugin_info
|| pc.m_library_path == s.options.print_plugin_info)
{
// load the plugin
auto p = inspector->register_plugin(pc.m_library_path);
auto p = inspector.register_plugin(pc.m_library_path);

// print plugin descriptive info
std::ostringstream os;
Expand All @@ -61,7 +61,7 @@ falco::app::run_result falco::app::actions::print_plugin_info(const falco::app::
os << schema << std::endl;
os << std::endl;
printf("%s", os.str().c_str());

// init the plugin
std::string err;
if (!p->init(pc.m_init_config, err))
Expand Down
5 changes: 2 additions & 3 deletions userspace/falco/app/actions/process_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static falco::app::run_result do_inspect(
}
else if(rc == SCAP_TIMEOUT)
{
if(unlikely(ev == nullptr))
if(ev == nullptr) [[unlikely]]
{
timeouts_since_last_success_or_msg++;
if(timeouts_since_last_success_or_msg > s.config->m_syscall_evt_timeout_max_consecutives
Expand Down Expand Up @@ -488,8 +488,7 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s)
ctxs.reserve(s.enabled_sources.size());
for (const auto& source : s.enabled_sources)
{
ctxs.emplace_back();
auto& ctx = ctxs[ctxs.size() - 1];
auto& ctx = ctxs.emplace_back();
ctx.source = source;
ctx.sync.reset(new source_sync_context(termination_sem));
auto src_info = s.source_infos.at(source);
Expand Down
Loading