mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-13 11:55:50 +00:00
refactor(userspace/falco): make signal handlers thread-safe
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
parent
f2aba88a6c
commit
34ca78786a
@ -90,13 +90,8 @@ application::run_result application::do_inspect(syscall_evt_drop_mgr &sdropmgr,
|
|||||||
|
|
||||||
writer.handle();
|
writer.handle();
|
||||||
|
|
||||||
if(m_state->reopen_outputs)
|
if(m_state->terminate.load(std::memory_order_acquire)
|
||||||
{
|
|| m_state->restart.load(std::memory_order_acquire))
|
||||||
m_state->outputs->reopen_outputs();
|
|
||||||
m_state->reopen_outputs = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m_state->terminate || m_state->restart)
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ application::run_result::~run_result()
|
|||||||
application::state::state()
|
application::state::state()
|
||||||
: restart(false),
|
: restart(false),
|
||||||
terminate(false),
|
terminate(false),
|
||||||
reopen_outputs(false),
|
|
||||||
enabled_sources({falco_common::syscall_source})
|
enabled_sources({falco_common::syscall_source})
|
||||||
{
|
{
|
||||||
config = std::make_shared<falco_configuration>();
|
config = std::make_shared<falco_configuration>();
|
||||||
@ -67,15 +66,17 @@ void application::terminate()
|
|||||||
{
|
{
|
||||||
if(m_state != nullptr)
|
if(m_state != nullptr)
|
||||||
{
|
{
|
||||||
m_state->terminate = true;
|
m_state->terminate.store(true, std::memory_order_release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void application::reopen_outputs()
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ void application::restart()
|
|||||||
{
|
{
|
||||||
if(m_state != nullptr)
|
if(m_state != nullptr)
|
||||||
{
|
{
|
||||||
m_state->restart = true;
|
m_state->restart.store(true, std::memory_order_release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ limitations under the License.
|
|||||||
#include "app_cmdline_options.h"
|
#include "app_cmdline_options.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace falco {
|
namespace falco {
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -61,9 +62,8 @@ private:
|
|||||||
state();
|
state();
|
||||||
virtual ~state();
|
virtual ~state();
|
||||||
|
|
||||||
bool restart;
|
std::atomic<bool> restart;
|
||||||
bool terminate;
|
std::atomic<bool> terminate;
|
||||||
bool reopen_outputs;
|
|
||||||
|
|
||||||
std::shared_ptr<falco_configuration> config;
|
std::shared_ptr<falco_configuration> config;
|
||||||
std::shared_ptr<falco_outputs> outputs;
|
std::shared_ptr<falco_outputs> outputs;
|
||||||
|
Loading…
Reference in New Issue
Block a user