From 6bd40f3ea29d1d759f513911b0f527d447058bd4 Mon Sep 17 00:00:00 2001 From: Andrea Terzolo Date: Tue, 12 Sep 2023 18:47:23 +0200 Subject: [PATCH] cleanup: thrown exceptions and avoid multiple logs Signed-off-by: Andrea Terzolo --- userspace/falco/falco_outputs.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/userspace/falco/falco_outputs.cpp b/userspace/falco/falco_outputs.cpp index ff77f1556e5..21bef081774 100644 --- a/userspace/falco/falco_outputs.cpp +++ b/userspace/falco/falco_outputs.cpp @@ -289,21 +289,25 @@ inline void falco_outputs::push(const ctrl_msg& cmsg) switch (m_outputs_queue_recovery) { case falco_common::RECOVERY_EXIT: - falco_logger::log(LOG_ERR, "Fatal error: Output queue out of memory. Exiting ..."); - exit(EXIT_FAILURE); + throw falco_exception("Fatal error: Output queue out of memory. Exiting ..."); case falco_common::RECOVERY_EMPTY: + /* Print a log just the first time */ + if(m_outputs_queue_num_drops.load() == 0) + { + falco_logger::log(LOG_ERR, "Output queue out of memory. Drop event plus events in queue due to emptying the queue; continue on ..."); + } m_outputs_queue_num_drops += m_queue.size() + 1; - falco_logger::log(LOG_ERR, "Output queue out of memory. Drop event plus events in queue due to emptying the queue; continue on ..."); m_queue.clear(); break; case falco_common::RECOVERY_CONTINUE: + if(m_outputs_queue_num_drops.load() == 0) + { + falco_logger::log(LOG_ERR, "Output queue out of memory. Drop event and continue on ..."); + } m_outputs_queue_num_drops++; - falco_logger::log(LOG_ERR, "Output queue out of memory. Drop event and continue on ..."); break; default: - falco_logger::log(LOG_ERR, "Fatal error: strategy unknown. Exiting ..."); - exit(EXIT_FAILURE); - break; + throw falco_exception("Fatal error: strategy unknown. Exiting ..."); } } #else