Skip to content

Commit

Permalink
Don't use logging in signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Feb 7, 2025
1 parent 9088fb2 commit 450db0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3329,15 +3329,12 @@ int main(int argc, char** argv)
}

ret = serviceMain(startupLog);
cerr << "serviceMain done" << endl;
{
std::lock_guard lock(g_doneRunning.mutex);
g_doneRunning.done = true;
g_doneRunning.condVar.notify_one();
}
cerr << "g_doneRunning notify done" << endl;
RecThreadInfo::joinThread0();
cerr << "joinThread0 done" << endl;
}
catch (const PDNSException& ae) {
SLOG(g_log << Logger::Error << "Exception: " << ae.reason << endl,
Expand Down
8 changes: 4 additions & 4 deletions pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1378,21 +1378,21 @@ void doExitGeneric(bool nicely)
#if defined(__SANITIZE_THREAD__)
_exit(0); // regression test check for exit 0
#endif
g_slog->withName("runtime")->info(Logr::Notice, "Exiting on user request");
// 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());

if (!g_pidfname.empty()) {
unlink(g_pidfname.c_str()); // we can at least try..
}

if (nicely) {
RecursorControlChannel::stop = true;
cerr << "locking g_doneRunning.mutex" << endl;
{
std::unique_lock lock(g_doneRunning.mutex);
cerr << "locked g_doneRunning.mutex" << endl;
g_doneRunning.condVar.wait(lock, [] { return g_doneRunning.done.load(); });
}
cerr << "done locking g_doneRunning.mutex" << endl;
// g_rcc.~RecursorControlChannel() do not call, caller still needs it!
}
else {
Expand Down

0 comments on commit 450db0b

Please sign in to comment.