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:
Leonardo Grasso
2020-11-25 12:33:36 +01:00
committed by poiana
parent f433b449d9
commit 9d31164a71

View File

@@ -52,12 +52,7 @@ falco_outputs::~falco_outputs()
{
if(m_initialized)
{
this->cleanup_outputs();
this->stop_worker();
if(m_worker_thread.joinable())
{
m_worker_thread.join();
}
for(auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it)
{
delete *it;
@@ -276,7 +271,19 @@ void falco_outputs::reopen_outputs()
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);
if(m_worker_thread.joinable())
{
m_worker_thread.join();
}
}
inline void falco_outputs::push(ctrl_msg_type cmt)
@@ -290,20 +297,17 @@ void falco_outputs::worker()
{
Watchdog<std::string> wd;
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;
falco_outputs::ctrl_msg cmsg;
while(true)
do
{
// Block until a message becomes available.
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)
{
wd.set_timeout(timeout, (*it)->get_name());
@@ -312,13 +316,14 @@ void falco_outputs::worker()
switch(cmsg.type)
{
case ctrl_msg_type::CTRL_MSG_OUTPUT:
(*it)->output(&cmsg);
(*it)->output(&cmsg);
break;
case ctrl_msg_type::CTRL_MSG_CLEANUP:
(*it)->cleanup();
case ctrl_msg_type::CTRL_MSG_STOP:
(*it)->cleanup();
break;
case ctrl_msg_type::CTRL_MSG_REOPEN:
(*it)->reopen();
(*it)->reopen();
break;
default:
falco_logger::log(LOG_DEBUG, "Outputs worker received an unknown message type\n");
@@ -330,5 +335,5 @@ void falco_outputs::worker()
}
}
wd.cancel_timeout();
}
} while(cmsg.type != ctrl_msg_type::CTRL_MSG_STOP);
}