mode, this is the Coordinator process.
Identified several commonly use process kinds and added the corresponding
Iam*Process() tests to avoid duplicating complex conditions throughout the
code. Note that kinds are not mutually exclusive. For example, a primary
process is also the master process and the worker process when running
in a no-daemon mode.
static void
serverConnectionsOpen(void)
{
- // Coordinator does not start proxying services
- if (!opt_no_daemon && Config.main_processes > 1 &&
- KidIdentifier == Config.main_processes + 1)
- return;
+ if (IamPrimaryProcess()) {
+#if USE_WCCP
+
+ wccpConnectionOpen();
+#endif
+#if USE_WCCPv2
+
+ wccp2ConnectionOpen();
+#endif
+ }
+ // Coordinator does not start proxying services
+ if (!IamCoordinatorProcess()) {
clientOpenListenSockets();
icpConnectionsOpen();
#if USE_HTCP
snmpConnectionOpen();
#endif
-#if USE_WCCP
-
- wccpConnectionOpen();
-#endif
-
-#if USE_WCCPv2
-
- wccp2ConnectionOpen();
-#endif
clientdbInit();
icmpEngine.Open();
carpInit();
peerUserHashInit();
peerSourceHashInit();
+ }
}
static void
serverConnectionsClose(void)
{
assert(shutting_down || reconfiguring);
+
+ if (IamPrimaryProcess()) {
+#if USE_WCCP
+
+ wccpConnectionClose();
+#endif
+#if USE_WCCPv2
+
+ wccp2ConnectionClose();
+#endif
+ }
+ if (!IamCoordinatorProcess()) {
clientHttpConnectionsClose();
icpConnectionShutdown();
#if USE_HTCP
snmpConnectionShutdown();
#endif
-#if USE_WCCP
-
- wccpConnectionClose();
-#endif
-#if USE_WCCPv2
-
- wccp2ConnectionClose();
-#endif
asnFreeMemory();
+ }
}
static void
redirectInit();
authenticateInit(&Config.authConfiguration);
externalAclInit();
+
+ if (IamPrimaryProcess()) {
#if USE_WCCP
wccpInit();
wccp2Init();
#endif
+ }
serverConnectionsOpen();
// moved to PconnModule::PconnModule()
}
+ if (IamPrimaryProcess()) {
#if USE_WCCP
wccpInit();
wccp2Init();
#endif
+ }
serverConnectionsOpen();
mainLoop.setTimeService(&time_engine);
- if (!opt_no_daemon && Config.main_processes > 1) {
- if (KidIdentifier == Config.main_processes + 1)
- AsyncJob::AsyncStart(Ipc::Coordinator::Instance());
- else if (KidIdentifier != 0)
- AsyncJob::AsyncStart(new Ipc::Strand);
- }
+ if (IamCoordinatorProcess())
+ AsyncJob::AsyncStart(Ipc::Coordinator::Instance());
+ else if (UsingSmp() && IamWorkerProcess())
+ AsyncJob::AsyncStart(new Ipc::Strand);
/* at this point we are finished the synchronous startup. */
starting_up = 0;
checkRunningPid(void)
{
// master process must start alone, but its kids processes may co-exist
- if (KidIdentifier != 0)
+ if (!IamMasterProcess())
return 0;
pid_t pid;
int nullfd;
- if (KidIdentifier != 0)
+ if (!IamMasterProcess())
return;
openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
#endif
- if (IsPidFileMaintainer()) {
+ if (IamPrimaryProcess()) {
if (Config.pidFilename && strcmp(Config.pidFilename, "none") != 0) {
enter_suid();
safeunlink(Config.pidFilename, 0);
SQUIDCEXTERN void keepCapabilities(void);
SQUIDCEXTERN void BroadcastSignalIfAny(int& sig);
-SQUIDCEXTERN bool IsPidFileMaintainer();
+/// whether the current process is the parent of all other Squid processes
+SQUIDCEXTERN bool IamMasterProcess();
+/**
+ whether the current process is dedicated to doing things that only
+ a single process should do, such as PID file maintenance and WCCP
+*/
+SQUIDCEXTERN bool IamPrimaryProcess();
+/// whether the current process coordinates worker processes
+SQUIDCEXTERN bool IamCoordinatorProcess();
+/// whether the current process handles HTTP transactions and such
+SQUIDCEXTERN bool IamWorkerProcess();
+/// Whether there should be more than one worker process running
+SQUIDCEXTERN bool UsingSmp(); // try using specific Iam*() checks above first
SQUIDCEXTERN int DebugSignal;
/* AYJ debugs function to show locations being reset with memset() */
BroadcastSignalIfAny(int& sig)
{
if (sig > 0) {
- if (!opt_no_daemon && Config.main_processes > 1) {
- if (KidIdentifier == Config.main_processes + 1)
- Ipc::Coordinator::Instance()->broadcastSignal(sig);
- }
+ if (IamCoordinatorProcess())
+ Ipc::Coordinator::Instance()->broadcastSignal(sig);
sig = -1;
}
}
}
bool
-IsPidFileMaintainer()
+IamMasterProcess()
{
- if (!opt_no_daemon && Config.main_processes > 0) {
- if (Config.main_processes > 1) {
- // multiple kids delegate PID file maintanence to the coordinator
- if (KidIdentifier <= Config.main_processes)
- return false;
- } else {
- // master process does not maintain PID file when
- // Config.main_processes == 1
- if (KidIdentifier == 0)
- return false;
- }
- }
+ return KidIdentifier == 0;
+}
+
+bool
+IamWorkerProcess()
+{
+ // when there is only one process, it has to be the worker
+ if (opt_no_daemon || Config.main_processes == 0)
+ return true;
+
+ return 0 < KidIdentifier && KidIdentifier <= Config.main_processes;
+}
+
+bool
+UsingSmp()
+{
+ return !opt_no_daemon && Config.main_processes > 1;
+}
+
+bool
+IamCoordinatorProcess()
+{
+ return UsingSmp() && KidIdentifier == Config.main_processes + 1;
+}
+
+bool
+IamPrimaryProcess()
+{
+ // when there is only one process, it has to be primary
+ if (opt_no_daemon || Config.main_processes == 0)
+ return true;
+
+ // when there is a master and worker process, the master delegates
+ // primary functions to its only kid
+ if (Config.main_processes == 1)
+ return IamWorkerProcess();
- // if there are no kids, then the master process maintains the PID file
- return true;
+ // in SMP mode, multiple kids delegate primary functions to the coordinator
+ return IamCoordinatorProcess();
}
void
mode_t old_umask;
char buf[32];
- if (!IsPidFileMaintainer())
+ if (!IamPrimaryProcess())
return;
if ((f = Config.pidFilename) == NULL)