Skip to content

Commit

Permalink
refactor(userspace/falco): make signal handlers thread-safe
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Aug 26, 2022
1 parent f2aba88 commit 34ca787
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
9 changes: 2 additions & 7 deletions userspace/falco/app_actions/process_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,8 @@ application::run_result application::do_inspect(syscall_evt_drop_mgr &sdropmgr,

writer.handle();

if(m_state->reopen_outputs)
{
m_state->outputs->reopen_outputs();
m_state->reopen_outputs = false;
}

if(m_state->terminate || m_state->restart)
if(m_state->terminate.load(std::memory_order_acquire)
|| m_state->restart.load(std::memory_order_acquire))
{
break;
}
Expand Down
11 changes: 6 additions & 5 deletions userspace/falco/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ application::run_result::~run_result()
application::state::state()
: restart(false),
terminate(false),
reopen_outputs(false),
enabled_sources({falco_common::syscall_source})
{
config = std::make_shared<falco_configuration>();
Expand All @@ -67,23 +66,25 @@ void application::terminate()
{
if(m_state != nullptr)
{
m_state->terminate = true;
m_state->terminate.store(true, std::memory_order_release);
}
}

void application::reopen_outputs()
{
if(m_state != nullptr)
if(m_state != nullptr && m_state->outputs != nullptr)
{
m_state->reopen_outputs = true;
// note: it is ok to do this inside the signal handler because
// in the current falco_outputs implementation this is non-blocking
m_state->outputs->reopen_outputs();
}
}

void application::restart()
{
if(m_state != nullptr)
{
m_state->restart = true;
m_state->restart.store(true, std::memory_order_release);
}
}

Expand Down
6 changes: 3 additions & 3 deletions userspace/falco/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#include "app_cmdline_options.h"

#include <string>
#include <atomic>

namespace falco {
namespace app {
Expand Down Expand Up @@ -61,9 +62,8 @@ class application {
state();
virtual ~state();

bool restart;
bool terminate;
bool reopen_outputs;
std::atomic<bool> restart;
std::atomic<bool> terminate;

std::shared_ptr<falco_configuration> config;
std::shared_ptr<falco_outputs> outputs;
Expand Down

0 comments on commit 34ca787

Please sign in to comment.