]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Clearly separate signal handling from rec_control quit(-nicely) path
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 12 Feb 2025 09:17:30 +0000 (10:17 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 12 Feb 2025 09:21:57 +0000 (10:21 +0100)
Also: as the bulk and regression tests now use quit-nicely, we don't need to do special processing
for the SAN case anymore on signals.

rec_control quit still does some SAN work and exits 1 (legacy beheviour).

pdns/recursordist/rec-main.cc
pdns/recursordist/rec_channel.hh
pdns/recursordist/rec_channel_rec.cc

index 00b1b8f67bb463707c0fcbaadfa0aaed4044301e..8ad01ea68feb296c342f09f15e7dcd03c680bf61 100644 (file)
@@ -952,7 +952,7 @@ static void daemonize(Logr::log_t log)
 
 static void termIntHandler([[maybe_unused]] int arg)
 {
-  doExit();
+  _exit(1);
 }
 
 static void usr1Handler([[maybe_unused]] int arg)
@@ -1962,10 +1962,6 @@ static int initForks(Logr::log_t log)
     signal(SIGTERM, termIntHandler);
     signal(SIGINT, termIntHandler);
   }
-#if defined(__SANITIZE_THREAD__) || (defined(__SANITIZE_ADDRESS__) && defined(HAVE_LEAK_SANITIZER_INTERFACE))
-  // If san is wanted, we dump the info ourselves
-  signal(SIGTERM, termIntHandler);
-#endif
 
   signal(SIGUSR1, usr1Handler);
   signal(SIGUSR2, usr2Handler);
index f9977e5892477a238294660a20efb794a2774e5e..f86092107c7a3396c37894d2e8f86ccc28dd7fe0 100644 (file)
@@ -139,8 +139,6 @@ void disableStats(StatComponent component, const string& stats);
 
 void registerAllStats();
 
-void doExitGeneric(bool nicely);
-void doExit();
 void doExitNicely();
 RecursorControlChannel::Answer doQueueReloadLuaScript(vector<string>::const_iterator begin, vector<string>::const_iterator end);
 RecursorControlChannel::Answer luaconfig(bool broadcast);
index bf0b64a5aff7aa75de513d03b147ac1d5e1eb2e7..08d600089015e382d822bb2842bb5e21d5447f05 100644 (file)
@@ -1373,15 +1373,13 @@ static auto clearLuaScript()
   return doQueueReloadLuaScript(empty.begin(), empty.end());
 }
 
-void doExitGeneric(bool nicely)
+// This code SHOUD *NOT* BE CALLED BY SIGNAL HANDLERS anymore
+static void doExitGeneric(bool nicely)
 {
 #if defined(__SANITIZE_THREAD__)
   _exit(0); // regression test check for exit 0
 #endif
-  // Not safe from a signal handler!
-  // g_slog->withName("runtime")->info(Logr::Notice, "Exiting on user request")
-  static const string msg("Exiting on user request\n");
-  (void)write(STDERR_FILENO, msg.data(), msg.size());
+  g_slog->withName("runtime")->info(Logr::Notice, "Exiting on user request", "nicely", Logging::Loggable(nicely));
 
   if (!g_pidfname.empty()) {
     unlink(g_pidfname.c_str()); // we can at least try..
@@ -1394,8 +1392,10 @@ void doExitGeneric(bool nicely)
       g_doneRunning.condVar.wait(lock, [] { return g_doneRunning.done.load(); });
     }
     // g_rcc.~RecursorControlChannel() do not call, caller still needs it!
+    // Caller will continue doing the orderly shutdown
   }
   else {
+    // rec_control quit case. Is that still used by test code? bulktests and regression test use quit-nicely
     g_rcc.~RecursorControlChannel();
 #if defined(__SANITIZE_ADDRESS__) && defined(HAVE_LEAK_SANITIZER_INTERFACE)
     clearLuaScript();
@@ -1409,7 +1409,7 @@ void doExitGeneric(bool nicely)
   }
 }
 
-void doExit()
+static void doExit()
 {
   doExitGeneric(false);
 }