From: Otto Moerbeek Date: Wed, 21 Jun 2023 08:24:45 +0000 (+0200) Subject: rec: Backport of 12928 to rec-4.9.x: fix daemonize() X-Git-Tag: rec-4.9.0~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b43e65f62fe6d68eb721aa5613edcc73b92f8ee;p=thirdparty%2Fpdns.git rec: Backport of 12928 to rec-4.9.x: fix daemonize() --- 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();