From b8d3e62e682943e6df56b406c210d4c77375a8a7 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 20 Jun 2023 09:01:21 +0200 Subject: [PATCH] rec: fix daemonize(), followup to #12836 Originally the code did not distinguish between parent return and error. --- pdns/recursordist/rec-main.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 5199df79c0..5d5b7c7c9b 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -809,7 +809,13 @@ static void setupNODGlobal() static void daemonize(Logr::log_t log) { - if (fork() < 0) { + 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 } -- 2.47.2