Skip to content

Commit

Permalink
Clearly separate signal handling from rec_control quit(-nicely) path
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
omoerbeek committed Feb 12, 2025
1 parent 0b138c3 commit aa21f61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
6 changes: 1 addition & 5 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions pdns/recursordist/rec_channel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 6 additions & 6 deletions pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand All @@ -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();
Expand All @@ -1409,7 +1409,7 @@ void doExitGeneric(bool nicely)
}
}

void doExit()
static void doExit()
{
doExitGeneric(false);
}
Expand Down

0 comments on commit aa21f61

Please sign in to comment.