mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-03 15:46:33 +00:00
update(userspace/falco): clear output queue if still blocked during the shutdown
Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com> Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
This commit is contained in:
@@ -52,12 +52,7 @@ falco_outputs::~falco_outputs()
|
|||||||
{
|
{
|
||||||
if(m_initialized)
|
if(m_initialized)
|
||||||
{
|
{
|
||||||
this->cleanup_outputs();
|
|
||||||
this->stop_worker();
|
this->stop_worker();
|
||||||
if(m_worker_thread.joinable())
|
|
||||||
{
|
|
||||||
m_worker_thread.join();
|
|
||||||
}
|
|
||||||
for(auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it)
|
for(auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it)
|
||||||
{
|
{
|
||||||
delete *it;
|
delete *it;
|
||||||
@@ -276,7 +271,19 @@ void falco_outputs::reopen_outputs()
|
|||||||
|
|
||||||
void falco_outputs::stop_worker()
|
void falco_outputs::stop_worker()
|
||||||
{
|
{
|
||||||
|
Watchdog<void *> wd;
|
||||||
|
wd.start([&](void *) -> void {
|
||||||
|
falco_logger::log(LOG_NOTICE, "output channels still blocked, discarding all remaining notifications\n");
|
||||||
|
m_queue.clear();
|
||||||
|
this->push(falco_outputs::ctrl_msg_type::CTRL_MSG_STOP);
|
||||||
|
});
|
||||||
|
wd.set_timeout(m_timeout, nullptr);
|
||||||
|
|
||||||
this->push(falco_outputs::ctrl_msg_type::CTRL_MSG_STOP);
|
this->push(falco_outputs::ctrl_msg_type::CTRL_MSG_STOP);
|
||||||
|
if(m_worker_thread.joinable())
|
||||||
|
{
|
||||||
|
m_worker_thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void falco_outputs::push(ctrl_msg_type cmt)
|
inline void falco_outputs::push(ctrl_msg_type cmt)
|
||||||
@@ -290,20 +297,17 @@ void falco_outputs::worker()
|
|||||||
{
|
{
|
||||||
Watchdog<std::string> wd;
|
Watchdog<std::string> wd;
|
||||||
wd.start([&](std::string payload) -> void {
|
wd.start([&](std::string payload) -> void {
|
||||||
falco_logger::log(LOG_CRIT, "\"" + payload + "\" output timeout, all output channels are blocked.\n");
|
falco_logger::log(LOG_CRIT, "\"" + payload + "\" output timeout, all output channels are blocked\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
auto timeout = m_timeout;
|
auto timeout = m_timeout;
|
||||||
|
|
||||||
falco_outputs::ctrl_msg cmsg;
|
falco_outputs::ctrl_msg cmsg;
|
||||||
while(true)
|
do
|
||||||
{
|
{
|
||||||
// Block until a message becomes available.
|
// Block until a message becomes available.
|
||||||
m_queue.pop(cmsg);
|
m_queue.pop(cmsg);
|
||||||
|
|
||||||
if (cmsg.type == ctrl_msg_type::CTRL_MSG_STOP)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it)
|
for(auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it)
|
||||||
{
|
{
|
||||||
wd.set_timeout(timeout, (*it)->get_name());
|
wd.set_timeout(timeout, (*it)->get_name());
|
||||||
@@ -312,13 +316,14 @@ void falco_outputs::worker()
|
|||||||
switch(cmsg.type)
|
switch(cmsg.type)
|
||||||
{
|
{
|
||||||
case ctrl_msg_type::CTRL_MSG_OUTPUT:
|
case ctrl_msg_type::CTRL_MSG_OUTPUT:
|
||||||
(*it)->output(&cmsg);
|
(*it)->output(&cmsg);
|
||||||
break;
|
break;
|
||||||
case ctrl_msg_type::CTRL_MSG_CLEANUP:
|
case ctrl_msg_type::CTRL_MSG_CLEANUP:
|
||||||
(*it)->cleanup();
|
case ctrl_msg_type::CTRL_MSG_STOP:
|
||||||
|
(*it)->cleanup();
|
||||||
break;
|
break;
|
||||||
case ctrl_msg_type::CTRL_MSG_REOPEN:
|
case ctrl_msg_type::CTRL_MSG_REOPEN:
|
||||||
(*it)->reopen();
|
(*it)->reopen();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
falco_logger::log(LOG_DEBUG, "Outputs worker received an unknown message type\n");
|
falco_logger::log(LOG_DEBUG, "Outputs worker received an unknown message type\n");
|
||||||
@@ -330,5 +335,5 @@ void falco_outputs::worker()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wd.cancel_timeout();
|
wd.cancel_timeout();
|
||||||
}
|
} while(cmsg.type != ctrl_msg_type::CTRL_MSG_STOP);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user