From: Otto Moerbeek Date: Tue, 20 Jun 2023 07:01:21 +0000 (+0200) Subject: rec: fix daemonize(), followup to #12836 X-Git-Tag: rec-5.0.0-alpha1~166^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8d3e62e682943e6df56b406c210d4c77375a8a7;p=thirdparty%2Fpdns.git rec: fix daemonize(), followup to #12836 Originally the code did not distinguish between parent return and error. --- 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 }