Skip to content

Commit

Permalink
update: apply clang format
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Susini <[email protected]>
  • Loading branch information
loresuso authored and poiana committed Nov 17, 2023
1 parent a968cb4 commit f141f6f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
10 changes: 6 additions & 4 deletions examples/syscall_async/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ class my_plugin
// (optional)
std::vector<std::string> get_async_event_sources() { return {"syscall"}; }

bool start_async_events(std::shared_ptr<falcosecurity::async_event_handler_factory> f)
bool start_async_events(
std::shared_ptr<falcosecurity::async_event_handler_factory> f)
{
m_async_thread_quit = false;
m_async_thread =
std::thread(&my_plugin::async_thread_loop, this, std::move(f->new_handler()));
m_async_thread = std::thread(&my_plugin::async_thread_loop, this,
std::move(f->new_handler()));
return true;
}

Expand All @@ -80,7 +81,8 @@ class my_plugin
return true;
}

void async_thread_loop(std::unique_ptr<falcosecurity::async_event_handler> h) noexcept
void async_thread_loop(
std::unique_ptr<falcosecurity::async_event_handler> h) noexcept
{
std::string msg;
uint64_t count = 0;
Expand Down
38 changes: 24 additions & 14 deletions include/falcosecurity/async_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class async_event_handler
public:
FALCOSECURITY_INLINE
async_event_handler(
falcosecurity::_internal::ss_plugin_owner_t* o,
const falcosecurity::_internal::ss_plugin_async_event_handler_t h): m_owner(o), m_handler(h), m_writer() {}
falcosecurity::_internal::ss_plugin_owner_t* o,
const falcosecurity::_internal::ss_plugin_async_event_handler_t h):
m_owner(o),
m_handler(h), m_writer()
{
}
FALCOSECURITY_INLINE
async_event_handler(async_event_handler&&) = default;
FALCOSECURITY_INLINE
Expand All @@ -44,17 +48,17 @@ class async_event_handler
async_event_handler& operator=(const async_event_handler& s) = delete;

FALCOSECURITY_INLINE
event_writer& writer()
{
return m_writer;
}
event_writer& writer() { return m_writer; }

FALCOSECURITY_INLINE
void push()
{
char err[PLUGIN_MAX_ERRLEN];
if(m_handler(m_owner, (const falcosecurity::_internal::ss_plugin_event*)m_writer.get_buf(),
err) != falcosecurity::_internal::ss_plugin_rc::SS_PLUGIN_SUCCESS)
if(m_handler(m_owner,
(const falcosecurity::_internal::ss_plugin_event*)
m_writer.get_buf(),
err) !=
falcosecurity::_internal::ss_plugin_rc::SS_PLUGIN_SUCCESS)
{
std::string msg = "async event handler failure";
if(*err != '\0')
Expand All @@ -72,27 +76,33 @@ class async_event_handler
event_writer m_writer;
};


class async_event_handler_factory
{
public:
FALCOSECURITY_INLINE
async_event_handler_factory(
falcosecurity::_internal::ss_plugin_owner_t* o,
const falcosecurity::_internal::ss_plugin_async_event_handler_t h): m_owner(o), m_handler(h) {}
falcosecurity::_internal::ss_plugin_owner_t* o,
const falcosecurity::_internal::ss_plugin_async_event_handler_t h):
m_owner(o),
m_handler(h)
{
}
FALCOSECURITY_INLINE
async_event_handler_factory(async_event_handler_factory&&) = default;
FALCOSECURITY_INLINE
async_event_handler_factory& operator=(async_event_handler_factory&&) = default;
async_event_handler_factory&
operator=(async_event_handler_factory&&) = default;
FALCOSECURITY_INLINE
async_event_handler_factory(const async_event_handler_factory& s) = default;
FALCOSECURITY_INLINE
async_event_handler_factory& operator=(const async_event_handler_factory& s) = default;
async_event_handler_factory&
operator=(const async_event_handler_factory& s) = default;

FALCOSECURITY_INLINE
std::unique_ptr<async_event_handler> new_handler() const
{
return std::unique_ptr<async_event_handler>(new async_event_handler(m_owner, m_handler));
return std::unique_ptr<async_event_handler>(
new async_event_handler(m_owner, m_handler));
}

private:
Expand Down
9 changes: 6 additions & 3 deletions include/falcosecurity/internal/plugin_mixin_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ template<class Plugin, class Base> class plugin_mixin_async : public Base
const ss_plugin_async_event_handler_t h)
{
static_assert(
std::is_same<bool (Plugin::*)(std::shared_ptr<async_event_handler_factory>),
std::is_same<bool (Plugin::*)(std::shared_ptr<
async_event_handler_factory>),
decltype(&Plugin::start_async_events)>::value,
"expected signature: bool "
"start_async_events(std::shared_ptr<async_event_handler_factory>)");
"start_async_events(std::shared_ptr<async_event_handler_"
"factory>)");
static_assert(std::is_same<bool (Plugin::*)() noexcept,
decltype(&Plugin::stop_async_events)>::value,
"expected signature: bool stop_async_events() noexcept");
Expand All @@ -118,7 +120,8 @@ template<class Plugin, class Base> class plugin_mixin_async : public Base

if(h)
{
m_handler_factory = std::make_shared<async_event_handler_factory>(o, h);
m_handler_factory =
std::make_shared<async_event_handler_factory>(o, h);
FALCOSECURITY_CATCH_ALL(Base::m_last_err_storage, {
if(!Plugin::start_async_events(m_handler_factory))
{
Expand Down

0 comments on commit f141f6f

Please sign in to comment.