chore(userspace/falco): make logging optional when terminating, restarting, and reopening outputs

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2022-10-12 10:23:48 +00:00 committed by poiana
parent 12d709b8b1
commit 7da30ca661
3 changed files with 19 additions and 10 deletions

View File

@ -411,7 +411,7 @@ application::run_result application::process_events()
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(); terminate(false);
termination_forced = true; termination_forced = true;
} }
for (auto &ctx : ctxs) for (auto &ctx : ctxs)

View File

@ -98,19 +98,25 @@ application::~application()
{ {
} }
void application::terminate() void application::terminate(bool verbose)
{ {
if (should_take_action_to_signal(falco::app::g_terminate)) if (should_take_action_to_signal(falco::app::g_terminate))
{ {
falco_logger::log(LOG_INFO, "SIGINT received, exiting...\n"); if (verbose)
{
falco_logger::log(LOG_INFO, "SIGINT received, exiting...\n");
}
} }
} }
void application::reopen_outputs() void application::reopen_outputs(bool verbose)
{ {
if (should_take_action_to_signal(falco::app::g_reopen_outputs)) if (should_take_action_to_signal(falco::app::g_reopen_outputs))
{ {
falco_logger::log(LOG_INFO, "SIGUSR1 received, reopening outputs...\n"); if (verbose)
{
falco_logger::log(LOG_INFO, "SIGUSR1 received, reopening outputs...\n");
}
if(m_state != nullptr && m_state->outputs != nullptr) if(m_state != nullptr && m_state->outputs != nullptr)
{ {
m_state->outputs->reopen_outputs(); m_state->outputs->reopen_outputs();
@ -119,11 +125,14 @@ void application::reopen_outputs()
} }
} }
void application::restart() void application::restart(bool verbose)
{ {
if (should_take_action_to_signal(falco::app::g_restart)) if (should_take_action_to_signal(falco::app::g_restart))
{ {
falco_logger::log(LOG_INFO, "SIGHUP received, restarting...\n"); if (verbose)
{
falco_logger::log(LOG_INFO, "SIGHUP received, restarting...\n");
}
} }
} }

View File

@ -322,9 +322,9 @@ private:
} }
// used in signal handlers to control the flow of the application // used in signal handlers to control the flow of the application
void terminate(); void terminate(bool verbose=true);
void restart(); void restart(bool verbose=true);
void reopen_outputs(); void reopen_outputs(bool verbose=true);
inline bool should_terminate() inline bool should_terminate()
{ {
return g_terminate.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET; return g_terminate.load(std::memory_order_seq_cst) != APP_SIGNAL_NOT_SET;