]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Better code coverage stats when enabled 11996/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 25 Feb 2022 15:15:56 +0000 (16:15 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 21 Sep 2022 14:52:05 +0000 (16:52 +0200)
When exiting on user request, dnsdist calls _Exit() to avoid any
issue caused by the order in which the destructors of our long-lived
objects are called (it would be nice to fix this properly, but it
would require a fairly large refactoring).
Since the static destructors are not called in that case, the most
recent coverage data is not always properly dumped to disk.
Explicitly calling __gcov_dump` before exiting ensures that no data
is lost.

pdns/dnsdist-lua.cc
pdns/dnsdist.cc

index c81cb6cbdecd37cae51e81810b65e98deaa71652..884c0f5d11ff0367171699a52e634651e421e2d2 100644 (file)
@@ -310,6 +310,13 @@ static void LuaThread(const std::string code)
   }
 }
 
+#ifdef COVERAGE
+extern "C"
+{
+  void __gcov_dump(void);
+}
+#endif
+
 static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
 {
   typedef LuaAssociativeTable<boost::variant<bool, std::string, LuaArray<std::string>, DownstreamState::checkfunc_t>> newserver_t;
@@ -894,14 +901,17 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
     sd_notify(0, "STOPPING=1");
 #endif /* HAVE_SYSTEMD */
 #if 0
-      // Useful for debugging leaks, but might lead to race under load
-      // since other threads are still running.
-      for(auto& frontend : g_tlslocals) {
-        frontend->cleanup();
-      }
-      g_tlslocals.clear();
-      g_rings.clear();
+    // Useful for debugging leaks, but might lead to race under load
+    // since other threads are still running.
+    for (auto& frontend : g_tlslocals) {
+      frontend->cleanup();
+    }
+    g_tlslocals.clear();
+    g_rings.clear();
 #endif /* 0 */
+#ifdef COVERAGE
+    __gcov_dump();
+#endif
     _exit(0);
   });
 
index dcbfc9e1c62f04494c647eab28144c677f70c499..710a9e2cdf7f660f2ad9ac35e725bcbb8c07d847 100644 (file)
@@ -2238,6 +2238,11 @@ static void usage()
 }
 
 #ifdef COVERAGE
+extern "C"
+{
+  void __gcov_dump(void);
+}
+
 static void cleanupLuaObjects()
 {
   /* when our coverage mode is enabled, we need to make
@@ -2254,7 +2259,8 @@ static void cleanupLuaObjects()
 static void sigTermHandler(int)
 {
   cleanupLuaObjects();
-  exit(EXIT_SUCCESS);
+  __gcov_dump();
+  _exit(EXIT_SUCCESS);
 }
 #else /* COVERAGE */
 static void sigTermHandler(int)