From 6b43e65f62fe6d68eb721aa5613edcc73b92f8ee Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 21 Jun 2023 10:24:45 +0200 Subject: [PATCH] rec: Backport of 12928 to rec-4.9.x: fix daemonize() --- pdns/recursordist/rec-main.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 1b54fa7fa9..d018a0a9b4 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -809,8 +809,14 @@ static void setupNODGlobal() static void daemonize(Logr::log_t log) { - if (fork() < 0) { - exit(0); // NOLINT(concurrency-mt-unsafe + if (auto pid = fork(); pid != 0) { + if (pid < 0) { + int err = errno; + SLOG(g_log << Logger::Critical << "Fork failed: " << stringerror(err) << endl, + log->error(Logr::Critical, err, "Fork failed")); + exit(1); // NOLINT(concurrency-mt-unsafe) + } + exit(0); // NOLINT(concurrency-mt-unsafe) } setsid(); -- 2.47.2