mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-29 08:07:24 +00:00
refactor(userspace/falco): adapt actions to new signal handler constructs
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
parent
eb3bf7260d
commit
70c22c7d2e
@ -36,20 +36,17 @@ static int inot_fd;
|
|||||||
|
|
||||||
static void terminate_signal_handler(int signal)
|
static void terminate_signal_handler(int signal)
|
||||||
{
|
{
|
||||||
ASSERT(falco::app::g_terminate.is_lock_free());
|
falco::app::g_terminate_signal.trigger();
|
||||||
falco::app::g_terminate.store(APP_SIGNAL_SET, std::memory_order_seq_cst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reopen_outputs_signal_handler(int signal)
|
static void reopen_outputs_signal_handler(int signal)
|
||||||
{
|
{
|
||||||
ASSERT(falco::app::g_reopen_outputs.is_lock_free());
|
falco::app::g_reopen_outputs_signal.trigger();
|
||||||
falco::app::g_reopen_outputs.store(APP_SIGNAL_SET, std::memory_order_seq_cst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restart_signal_handler(int signal)
|
static void restart_signal_handler(int signal)
|
||||||
{
|
{
|
||||||
ASSERT(falco::app::g_restart.is_lock_free());
|
falco::app::g_restart_signal.trigger();
|
||||||
falco::app::g_restart.store(APP_SIGNAL_SET, std::memory_order_seq_cst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool create_handler(int sig, void (*func)(int), run_result &ret)
|
bool create_handler(int sig, void (*func)(int), run_result &ret)
|
||||||
@ -74,13 +71,13 @@ bool create_handler(int sig, void (*func)(int), run_result &ret)
|
|||||||
|
|
||||||
falco::app::run_result falco::app::actions::create_signal_handlers(falco::app::state& s)
|
falco::app::run_result falco::app::actions::create_signal_handlers(falco::app::state& s)
|
||||||
{
|
{
|
||||||
falco::app::g_terminate.store(APP_SIGNAL_NOT_SET, std::memory_order_seq_cst);
|
falco::app::g_terminate_signal.reset();
|
||||||
falco::app::g_restart.store(APP_SIGNAL_NOT_SET, std::memory_order_seq_cst);
|
falco::app::g_restart_signal.reset();
|
||||||
falco::app::g_reopen_outputs.store(APP_SIGNAL_NOT_SET, std::memory_order_seq_cst);
|
falco::app::g_reopen_outputs_signal.reset();
|
||||||
|
|
||||||
if (!g_terminate.is_lock_free()
|
if (!g_terminate_signal.is_lock_free()
|
||||||
|| !g_restart.is_lock_free()
|
|| !g_restart_signal.is_lock_free()
|
||||||
|| !g_reopen_outputs.is_lock_free())
|
|| !g_reopen_outputs_signal.is_lock_free())
|
||||||
{
|
{
|
||||||
falco_logger::log(LOG_WARNING, "Bundled atomics implementation is not lock-free, signal handlers may be unstable\n");
|
falco_logger::log(LOG_WARNING, "Bundled atomics implementation is not lock-free, signal handlers may be unstable\n");
|
||||||
}
|
}
|
||||||
|
@ -187,25 +187,30 @@ static falco::app::run_result do_inspect(
|
|||||||
{
|
{
|
||||||
rc = inspector->next(&ev);
|
rc = inspector->next(&ev);
|
||||||
|
|
||||||
if (should_reopen_outputs())
|
if (falco::app::g_reopen_outputs_signal.triggered())
|
||||||
{
|
{
|
||||||
falco::app::reopen_outputs([&s]()
|
falco::app::g_reopen_outputs_signal.handle([&s](){
|
||||||
|
falco_logger::log(LOG_INFO, "SIGUSR1 received, reopening outputs...\n");
|
||||||
|
if(s.outputs != nullptr)
|
||||||
{
|
{
|
||||||
if(s.outputs != nullptr)
|
s.outputs->reopen_outputs();
|
||||||
{
|
}
|
||||||
s.outputs->reopen_outputs();
|
falco::app::g_reopen_outputs_signal.reset();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(should_terminate())
|
if(falco::app::g_terminate_signal.triggered())
|
||||||
{
|
{
|
||||||
falco::app::terminate();
|
falco::app::g_terminate_signal.handle([&](){
|
||||||
|
falco_logger::log(LOG_INFO, "SIGINT received, exiting...\n");
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(should_restart())
|
else if(falco::app::g_restart_signal.triggered())
|
||||||
{
|
{
|
||||||
falco::app::restart();
|
falco::app::g_restart_signal.handle([&](){
|
||||||
|
falco_logger::log(LOG_INFO, "SIGHUP received, restarting...\n");
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(rc == SCAP_TIMEOUT)
|
else if(rc == SCAP_TIMEOUT)
|
||||||
@ -498,7 +503,8 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s)
|
|||||||
if (!res.success && !termination_forced)
|
if (!res.success && !termination_forced)
|
||||||
{
|
{
|
||||||
falco_logger::log(LOG_INFO, "An error occurred in an event source, forcing termination...\n");
|
falco_logger::log(LOG_INFO, "An error occurred in an event source, forcing termination...\n");
|
||||||
terminate(false);
|
falco::app::g_terminate_signal.trigger();
|
||||||
|
falco::app::g_terminate_signal.handle([&](){});
|
||||||
termination_forced = true;
|
termination_forced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user