]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4914: Do not call setsid() in --foreground mode (#354)
authorMarcos Mello <marcosfrm@users.noreply.github.com>
Wed, 23 Jan 2019 15:18:43 +0000 (15:18 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 23 Jan 2019 15:35:32 +0000 (15:35 +0000)
Squid executed in --foreground is always a process group leader. Thus,
setsid(2) is unnecessary and always fails (with EPERM) for such Squids.

src/main.cc

index d9f423ed67dd568a8d3ded07b6c3508ea884010f..97e1315ecf0484622f2abda18a0225336e10c601 100644 (file)
@@ -1866,6 +1866,7 @@ GoIntoBackground()
         exit(EXIT_SUCCESS);
     }
     // child, running as a background daemon
+    Must(setsid() > 0); // ought to succeed after fork()
 }
 
 static void
@@ -1911,14 +1912,6 @@ watch_child(const CommandLine &masterCommand)
     if (!opt_foreground)
         GoIntoBackground();
 
-    // TODO: Fails with --foreground if the calling process is process group
-    //       leader, which is always (?) the case. Should probably moved to
-    //       GoIntoBackground and executed only after successfully forking
-    if (setsid() < 0) {
-        int xerrno = errno;
-        syslog(LOG_ALERT, "setsid failed: %s", xstrerr(xerrno));
-    }
-
     closelog();
 
 #ifdef TIOCNOTTY