From: Otto Moerbeek Date: Mon, 11 Nov 2019 11:34:56 +0000 (+0100) Subject: Make threads run until asked to stop. X-Git-Tag: dnsdist-1.4.0~7^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8657c2af898ca06a484856091e975e0e4f58d512;p=thirdparty%2Fpdns.git Make threads run until asked to stop. This is safer since the atexit handler is not ran while threads are still active. Also, when using valgrind we get more clean leak reports. Retry if the accidentally merged #8518 that was reverted. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d36625e4d9..c6200a1e5f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4279,6 +4279,8 @@ static int serviceMain(int argc, char*argv[]) infos.isListener = true; infos.isWorker = true; recursorThread(currentThreadId++, "worker"); + + handlerInfos.thread.join(); } else { @@ -4313,7 +4315,9 @@ static int serviceMain(int argc, char*argv[]) infos.isHandler = true; infos.thread = std::thread(recursorThread, 0, "web+stat"); - s_threadInfos.at(0).thread.join(); + for (auto & ti : s_threadInfos) { + ti.thread.join(); + } } return 0; } @@ -4448,7 +4452,8 @@ try time_t carbonInterval=::arg().asNum("carbon-interval"); time_t luaMaintenanceInterval=::arg().asNum("lua-maintenance-interval"); counter.store(0); // used to periodically execute certain tasks - for(;;) { + + while (!RecursorControlChannel::stop) { while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing if(!(counter%500)) { @@ -4516,6 +4521,7 @@ try } } } + return 0; } catch(PDNSException &ae) { g_log< #include #include +#include #include #include "iputils.hh" #include "dnsname.hh" @@ -53,6 +54,7 @@ public: std::string recv(std::string* remote=0, unsigned int timeout=5); int d_fd; + static volatile sig_atomic_t stop; private: struct sockaddr_un d_local; }; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index a86500ba12..a294e62ac7 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1165,15 +1165,16 @@ void doExitGeneric(bool nicely) { g_log<