Commit 1344cf98 authored by Loïc Yhuel's avatar Loïc Yhuel Committed by Arjen Hiemstra
Browse files

Fix ksgrd_network_helper crash on exit afer a failure

On an early return in main, the ConnectionMapping thread was destroyed without being
properly joined, leading to an abort.
So ConnectionMapping::stop has been changed into a destructor.

m_running is also now set from the main thread, to ensure any early destruction while the
thread is starting stops it properly.

BUG: 444921


(cherry picked from commit 457bac23)
parent 203b72c2
......@@ -82,9 +82,19 @@ int parseInetDiagMesg(struct nl_msg *msg, void *arg)
ConnectionMapping::ConnectionMapping()
{
m_running = true;
m_thread = std::thread(&ConnectionMapping::loop, this);
}
ConnectionMapping::~ConnectionMapping()
{
m_running = false;
if (m_thread.joinable()) {
m_thread.join();
}
}
ConnectionMapping::PacketResult ConnectionMapping::pidForPacket(const Packet &packet)
{
std::lock_guard<std::mutex> lock{m_mutex};
......@@ -116,14 +126,6 @@ ConnectionMapping::PacketResult ConnectionMapping::pidForPacket(const Packet &pa
return result;
}
void ConnectionMapping::stop()
{
m_running = false;
if (m_thread.joinable()) {
m_thread.join();
}
}
void ConnectionMapping::loop()
{
std::unique_ptr<nl_sock, decltype(&nl_socket_free)> socket{nl_socket_alloc(), nl_socket_free};
......@@ -131,8 +133,6 @@ void ConnectionMapping::loop()
nl_connect(socket.get(), NETLINK_SOCK_DIAG);
nl_socket_modify_cb(socket.get(), NL_CB_VALID, NL_CB_CUSTOM, &parseInetDiagMesg, this);
m_running = true;
while (m_running) {
m_seenAddresses.clear();
m_seenInodes.clear();
......
......@@ -35,11 +35,10 @@ public:
};
ConnectionMapping();
~ConnectionMapping();
PacketResult pidForPacket(const Packet &packet);
void stop();
private:
struct State {
State &operator=(const State &other)
......
......@@ -88,7 +88,6 @@ int main(int argc, char **argv)
accumulator->stop();
capture->stop();
mapping->stop();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment