]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Backport of 12928 to rec-4.9.x: fix daemonize() 12932/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Jun 2023 08:24:45 +0000 (10:24 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Jun 2023 08:28:04 +0000 (10:28 +0200)
pdns/recursordist/rec-main.cc

index 1b54fa7fa938e1f3c189734abe011c01e91cfa6b..d018a0a9b45f29deadef47179ff2551e586627c6 100644 (file)
@@ -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();