]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: fix daemonize(), followup to #12836
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Jun 2023 07:01:21 +0000 (09:01 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Jun 2023 07:01:21 +0000 (09:01 +0200)
Originally the code did not distinguish between parent return and error.

pdns/recursordist/rec-main.cc

index 5199df79c022882ba3ba06fe3e31c548dfe9b928..5d5b7c7c9b181bc6270a1dad471176bdad3060cc 100644 (file)
@@ -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
   }