]> 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)
committerAmos Jeffries <yadij@users.noreply.github.com>
Mon, 28 Jan 2019 05:11:46 +0000 (18:11 +1300)
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 7f5ec8015f2bd0a128a46375fa5c521c7910b79a..1e8e035f4c9f165e791bbf099f54031ffa759ede 100644 (file)
@@ -1871,6 +1871,7 @@ GoIntoBackground()
         exit(EXIT_SUCCESS);
     }
     // child, running as a background daemon
+    Must(setsid() > 0); // ought to succeed after fork()
 }
 
 static void
@@ -1916,14 +1917,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