mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-08 10:09:40 +00:00
Convert direct pointer refs to shared_ptr
Some objects used by falco (falco outputs, falco_formats, etc) were using raw pointer references, which isn't great. So convert use of raw pointers (originally passed from falco_init or functions it called) with shared_ptr, as they are now held in application state. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ limitations under the License.
|
||||
#include "falco_engine.h"
|
||||
#include "banned.h" // This raises a compilation error when certain functions are used
|
||||
|
||||
falco_formats::falco_formats(falco_engine *engine,
|
||||
falco_formats::falco_formats(std::shared_ptr<falco_engine> engine,
|
||||
bool json_include_output_property,
|
||||
bool json_include_tags_property)
|
||||
: m_falco_engine(engine),
|
||||
|
@@ -24,7 +24,7 @@ limitations under the License.
|
||||
class falco_formats
|
||||
{
|
||||
public:
|
||||
falco_formats(falco_engine *engine,
|
||||
falco_formats(std::shared_ptr<falco_engine> engine,
|
||||
bool json_include_output_property,
|
||||
bool json_include_tags_property);
|
||||
virtual ~falco_formats();
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
const std::string &format);
|
||||
|
||||
protected:
|
||||
falco_engine *m_falco_engine;
|
||||
std::shared_ptr<falco_engine> m_falco_engine;
|
||||
bool m_json_include_output_property;
|
||||
bool m_json_include_tags_property;
|
||||
};
|
||||
|
@@ -32,8 +32,8 @@ syscall_evt_drop_mgr::~syscall_evt_drop_mgr()
|
||||
{
|
||||
}
|
||||
|
||||
void syscall_evt_drop_mgr::init(sinsp *inspector,
|
||||
falco_outputs *outputs,
|
||||
void syscall_evt_drop_mgr::init(std::shared_ptr<sinsp> inspector,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
syscall_evt_drop_actions &actions,
|
||||
double threshold,
|
||||
double rate,
|
||||
@@ -55,7 +55,7 @@ void syscall_evt_drop_mgr::init(sinsp *inspector,
|
||||
}
|
||||
}
|
||||
|
||||
bool syscall_evt_drop_mgr::process_event(sinsp *inspector, sinsp_evt *evt)
|
||||
bool syscall_evt_drop_mgr::process_event(std::shared_ptr<sinsp> inspector, sinsp_evt *evt)
|
||||
{
|
||||
if(m_next_check_ts == 0)
|
||||
{
|
||||
|
@@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <sinsp.h>
|
||||
@@ -41,8 +42,8 @@ public:
|
||||
syscall_evt_drop_mgr();
|
||||
virtual ~syscall_evt_drop_mgr();
|
||||
|
||||
void init(sinsp *inspector,
|
||||
falco_outputs *outputs,
|
||||
void init(std::shared_ptr<sinsp> inspector,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
syscall_evt_drop_actions &actions,
|
||||
double threshold,
|
||||
double rate,
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
// event drops, and performing any actions.
|
||||
//
|
||||
// Returns whether event processing should continue or stop (with an error).
|
||||
bool process_event(sinsp *inspector, sinsp_evt *evt);
|
||||
bool process_event(std::shared_ptr<sinsp> inspector, sinsp_evt *evt);
|
||||
|
||||
void print_stats();
|
||||
|
||||
@@ -64,8 +65,8 @@ protected:
|
||||
|
||||
uint64_t m_num_syscall_evt_drops;
|
||||
uint64_t m_num_actions;
|
||||
sinsp *m_inspector;
|
||||
falco_outputs *m_outputs;
|
||||
std::shared_ptr<sinsp> m_inspector;
|
||||
std::shared_ptr<falco_outputs> m_outputs;
|
||||
syscall_evt_drop_actions m_actions;
|
||||
token_bucket m_bucket;
|
||||
uint64_t m_next_check_ts;
|
||||
|
@@ -60,7 +60,7 @@ falco_outputs::~falco_outputs()
|
||||
}
|
||||
}
|
||||
|
||||
void falco_outputs::init(falco_engine *engine,
|
||||
void falco_outputs::init(std::shared_ptr<falco_engine> engine,
|
||||
bool json_output,
|
||||
bool json_include_output_property,
|
||||
bool json_include_tags_property,
|
||||
|
@@ -39,7 +39,7 @@ public:
|
||||
falco_outputs();
|
||||
virtual ~falco_outputs();
|
||||
|
||||
void init(falco_engine *engine,
|
||||
void init(std::shared_ptr<falco_engine> engine,
|
||||
bool json_output,
|
||||
bool json_include_output_property,
|
||||
bool json_include_tags_property,
|
||||
|
@@ -31,7 +31,7 @@ static void timer_handler (int signum)
|
||||
extern char **environ;
|
||||
|
||||
StatsFileWriter::StatsFileWriter()
|
||||
: m_num_stats(0), m_inspector(NULL)
|
||||
: m_num_stats(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ StatsFileWriter::~StatsFileWriter()
|
||||
m_output.close();
|
||||
}
|
||||
|
||||
bool StatsFileWriter::init(sinsp *inspector, string &filename, uint32_t interval_msec, string &errstr)
|
||||
bool StatsFileWriter::init(std::shared_ptr<sinsp> inspector, string &filename, uint32_t interval_msec, string &errstr)
|
||||
{
|
||||
struct itimerval timer;
|
||||
struct sigaction handler;
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
virtual ~StatsFileWriter();
|
||||
|
||||
// Returns success as bool. On false fills in errstr.
|
||||
bool init(sinsp *inspector, std::string &filename,
|
||||
bool init(std::shared_ptr<sinsp> inspector, std::string &filename,
|
||||
uint32_t interval_msec,
|
||||
string &errstr);
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
|
||||
protected:
|
||||
uint32_t m_num_stats;
|
||||
sinsp *m_inspector;
|
||||
std::shared_ptr<sinsp> m_inspector;
|
||||
std::ofstream m_output;
|
||||
std::string m_extra;
|
||||
scap_stats m_last_stats;
|
||||
|
@@ -25,7 +25,7 @@ limitations under the License.
|
||||
using json = nlohmann::json;
|
||||
using namespace std;
|
||||
|
||||
k8s_audit_handler::k8s_audit_handler(falco_engine *engine, falco_outputs *outputs, std::size_t k8s_audit_event_source_idx):
|
||||
k8s_audit_handler::k8s_audit_handler(std::shared_ptr<falco_engine> engine, std::shared_ptr<falco_outputs> outputs, std::size_t k8s_audit_event_source_idx):
|
||||
m_engine(engine), m_outputs(outputs), m_k8s_audit_event_source_idx(k8s_audit_event_source_idx)
|
||||
{
|
||||
}
|
||||
@@ -43,8 +43,8 @@ bool k8s_healthz_handler::handleGet(CivetServer *server, struct mg_connection *c
|
||||
return true;
|
||||
}
|
||||
|
||||
bool k8s_audit_handler::accept_data(falco_engine *engine,
|
||||
falco_outputs *outputs,
|
||||
bool k8s_audit_handler::accept_data(std::shared_ptr<falco_engine> engine,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
std::size_t k8s_audit_event_source_idx,
|
||||
std::string &data,
|
||||
std::string &errstr)
|
||||
@@ -186,9 +186,9 @@ falco_webserver::~falco_webserver()
|
||||
stop();
|
||||
}
|
||||
|
||||
void falco_webserver::init(falco_configuration *config,
|
||||
falco_engine *engine,
|
||||
falco_outputs *outputs,
|
||||
void falco_webserver::init(std::shared_ptr<falco_configuration> config,
|
||||
std::shared_ptr<falco_engine> engine,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
std::size_t k8s_audit_event_source_idx)
|
||||
{
|
||||
m_config = config;
|
||||
|
@@ -27,20 +27,20 @@ limitations under the License.
|
||||
class k8s_audit_handler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
k8s_audit_handler(falco_engine *engine, falco_outputs *outputs, std::size_t k8s_audit_event_source_idx);
|
||||
k8s_audit_handler(std::shared_ptr<falco_engine> engine, std::shared_ptr<falco_outputs> outputs, std::size_t k8s_audit_event_source_idx);
|
||||
virtual ~k8s_audit_handler();
|
||||
|
||||
bool handleGet(CivetServer *server, struct mg_connection *conn);
|
||||
bool handlePost(CivetServer *server, struct mg_connection *conn);
|
||||
|
||||
static bool accept_data(falco_engine *engine,
|
||||
falco_outputs *outputs,
|
||||
static bool accept_data(std::shared_ptr<falco_engine> engine,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
std::size_t k8s_audit_event_source_idx,
|
||||
std::string &post_data, std::string &errstr);
|
||||
|
||||
private:
|
||||
falco_engine *m_engine;
|
||||
falco_outputs *m_outputs;
|
||||
std::shared_ptr<falco_engine> m_engine;
|
||||
std::shared_ptr<falco_outputs> m_outputs;
|
||||
std::size_t m_k8s_audit_event_source_idx;
|
||||
bool accept_uploaded_data(std::string &post_data, std::string &errstr);
|
||||
};
|
||||
@@ -65,18 +65,18 @@ public:
|
||||
falco_webserver();
|
||||
virtual ~falco_webserver();
|
||||
|
||||
void init(falco_configuration *config,
|
||||
falco_engine *engine,
|
||||
falco_outputs *outputs,
|
||||
void init(std::shared_ptr<falco_configuration> config,
|
||||
std::shared_ptr<falco_engine> engine,
|
||||
std::shared_ptr<falco_outputs> outputs,
|
||||
std::size_t k8s_audit_event_source_idx);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
falco_engine *m_engine;
|
||||
falco_configuration *m_config;
|
||||
falco_outputs *m_outputs;
|
||||
std::shared_ptr<falco_engine> m_engine;
|
||||
std::shared_ptr<falco_configuration> m_config;
|
||||
std::shared_ptr<falco_outputs> m_outputs;
|
||||
std::size_t m_k8s_audit_event_source_idx;
|
||||
unique_ptr<CivetServer> m_server;
|
||||
unique_ptr<k8s_audit_handler> m_k8s_audit_handler;
|
||||
|
Reference in New Issue
Block a user