main.cc File Reference
#include "squid.h"
#include "AccessLogEntry.h"
#include "acl/Asn.h"
#include "acl/forward.h"
#include "anyp/UriScheme.h"
#include "auth/Config.h"
#include "auth/Gadgets.h"
#include "AuthReg.h"
#include "base/RunnersRegistry.h"
#include "base/Subscription.h"
#include "base/TextException.h"
#include "cache_cf.h"
#include "CachePeer.h"
#include "carp.h"
#include "client_db.h"
#include "client_side.h"
#include "comm.h"
#include "CommandLine.h"
#include "ConfigParser.h"
#include "CpuAffinity.h"
#include "debug/Messages.h"
#include "DiskIO/DiskIOModule.h"
#include "dns/forward.h"
#include "errorpage.h"
#include "event.h"
#include "EventLoop.h"
#include "ExternalACL.h"
#include "fd.h"
#include "format/Token.h"
#include "fqdncache.h"
#include "fs/Module.h"
#include "fs_io.h"
#include "FwdState.h"
#include "globals.h"
#include "htcp.h"
#include "http/Stream.h"
#include "HttpHeader.h"
#include "HttpReply.h"
#include "icmp/IcmpSquid.h"
#include "icmp/net_db.h"
#include "ICP.h"
#include "Instance.h"
#include "ip/tools.h"
#include "ipc/Coordinator.h"
#include "ipc/Kids.h"
#include "ipc/Strand.h"
#include "ipcache.h"
#include "mime.h"
#include "neighbors.h"
#include "parser/Tokenizer.h"
#include "Parsing.h"
#include "pconn.h"
#include "peer_sourcehash.h"
#include "peer_userhash.h"
#include "PeerSelectState.h"
#include "protos.h"
#include "redirect.h"
#include "refresh.h"
#include "sbuf/Stream.h"
#include "SBufStatsAction.h"
#include "SquidConfig.h"
#include "stat.h"
#include "StatCounters.h"
#include "Store.h"
#include "store/Disks.h"
#include "store_log.h"
#include "StoreFileSystem.h"
#include "time/Engine.h"
#include "tools.h"
#include "unlinkd.h"
#include "wccp.h"
#include "wccp2.h"
#include "WinSvc.h"
#include "adaptation/Config.h"
#include "adaptation/ecap/Config.h"
#include "adaptation/icap/Config.h"
#include "adaptation/icap/icap_log.h"
#include "ClientDelayConfig.h"
#include "DelayPools.h"
#include "LoadableModules.h"
#include "ssl/context_storage.h"
#include "ssl/helper.h"
#include "snmp_core.h"
#include <cerrno>
#include <process.h>

Go to the source code of this file.

Classes

class  StoreRootEngine
 
class  SignalEngine
 

Enumerations

enum  {
  optForeground = 2 ,
  optKid
}
 CommandLine option IDs for –long options that lack a short (-x) equivalent. More...
 

Functions

void WIN32_svcstatusupdate (DWORD, DWORD)
 
void WINAPI WIN32_svcHandler (DWORD)
 
static void mainRotate (void)
 
static void mainReconfigureStart (void)
 
static void mainReconfigureFinish (void *)
 
static void mainInitialize (void)
 
static void usage (void)
 
static void mainHandleCommandLineOption (const int optId, const char *optValue)
 
static void sendSignal (void)
 
static void serverConnectionsOpen (void)
 
static void serverConnectionsClose (void)
 
static void watch_child (const CommandLine &)
 
static void setEffectiveUser (void)
 
static void SquidShutdown (void)
 
static void mainSetCwd (void)
 set the working directory. More...
 
static bool AvoidSignalAction (const char *description, volatile int &signalVar)
 
void rotate_logs (int sig)
 
void reconfigure (int sig)
 
static void master_revive_kids (int sig)
 
static void master_shutdown (int sig)
 Shutdown signal handler for master process. More...
 
void shut_down (int sig)
 
void sig_child (int sig)
 
static bool mainChangeDir (const char *dir)
 changes working directory, providing error reporting More...
 
static void OnTerminate ()
 
int SquidMain (int argc, char **argv)
 unsafe main routine – may throw More...
 
static int SquidMainSafe (int argc, char **argv)
 unsafe main routine wrapper to catch exceptions More...
 
void WINAPI SquidWinSvcMain (int argc, char **argv)
 
int main (int argc, char **argv)
 
static void ConfigureCurrentKid (const CommandLine &cmdLine)
 computes name and ID for the current kid process More...
 
static void ConfigureDebugging ()
 Start directing debugs() messages to the configured cache.log. More...
 
static void RunConfigUsers ()
 
static void StartUsingConfig ()
 
static void RegisterModules ()
 register all known modules for handling future RegisteredRunner events More...
 
static void mainStartScript (const char *prog)
 
static void masterShutdownStart ()
 Initiates shutdown sequence. Shutdown ends when the last running kids stops. More...
 
static void masterReconfigureStart ()
 Initiates reconfiguration sequence. See also: masterReconfigureFinish(). More...
 
static void masterReconfigureFinish ()
 Ends reconfiguration sequence started by masterReconfigureStart(). More...
 
static void masterReviveKids ()
 Reacts to the kid revival alarm. More...
 
static void masterCheckAndBroadcastSignals ()
 
static void masterMaintainKidRevivalSchedule ()
 
static bool masterSignaled ()
 
static void GoIntoBackground ()
 makes the caller a daemon process running in the background More...
 
static void masterExit ()
 

Variables

static int opt_install_service = FALSE
 
static int opt_remove_service = FALSE
 
static int opt_command_line = FALSE
 
static int opt_signal_service = FALSE
 
static char * opt_syslog_facility = nullptr
 
static int icpPortNumOverride = 1
 
static int configured_once = 0
 
static volatile int do_reconfigure = 0
 
static volatile int do_rotate = 0
 
static volatile int do_shutdown = 0
 
static volatile int do_revive_kids = 0
 
static volatile int shutdown_status = EXIT_SUCCESS
 
static volatile int do_handle_stopped_child = 0
 
static int RotateSignal = -1
 
static int ReconfigureSignal = -1
 
static int ShutdownSignal = -1
 
static int ReviveKidsSignal = -1
 
static const char * squid_start_script = "squid_start"
 
static const char * shortOpStr
 
static struct option squidOptions []
 
bool Chrooted = false
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
optForeground 
optKid 

Definition at line 382 of file main.cc.

Function Documentation

◆ AvoidSignalAction()

static bool AvoidSignalAction ( const char *  description,
volatile int signalVar 
)
static

Decides whether the signal-controlled action X should be delayed, canceled, or executed immediately. Clears do_X (via signalVar) as needed.

Definition at line 241 of file main.cc.

References configured_once, DBG_IMPORTANT, debugs, reconfiguring, and shutting_down.

Referenced by SignalEngine::doShutdown(), mainReconfigureStart(), mainRotate(), masterReconfigureStart(), masterReviveKids(), and masterShutdownStart().

◆ ConfigureCurrentKid()

◆ ConfigureDebugging()

static void ConfigureDebugging ( )
static

◆ GoIntoBackground()

static void GoIntoBackground ( )
static

Definition at line 1866 of file main.cc.

References Debug::ForgetSaved(), Must, pid, TexcHere, ToSBuf(), and xstrerr().

Referenced by watch_child().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1331 of file main.cc.

References opt_no_daemon, SquidMainSafe(), and WIN32_StartService().

◆ mainChangeDir()

static bool mainChangeDir ( const char *  dir)
static

Definition at line 1050 of file main.cc.

References DBG_CRITICAL, debugs, and xstrerr().

Referenced by mainSetCwd().

◆ mainHandleCommandLineOption()

static void mainHandleCommandLineOption ( const int  optId,
const char *  optValue 
)
static
C
Unset/disabel global option for catchign signals. opt_catch_signals
D
OBSOLETE: WAS: override to prevent optional startup DNS tests.
F
Set global option for foreground rebuild. opt_foreground_rebuild
N
Set global option for 'no_daemon' mode. opt_no_daemon
O
Set global option. opt_command_lin and WIN32_Command_Line
R
Unset/disable global option opt_reuseaddr
S
Set global option opt_store_doublecheck
X
Force full debugging
Y
Set global option opt_reload_hit_only
i
Set global option opt_install_service (to TRUE)
a
Add optional HTTP port as given following the option
d
debugs() messages with the given debugging level (and the more important ones) should be written to stderr
f
Load the file given instead of the default squid.conf.
k
Run the administrative action given following the option
  • When it is missing or an unknown option display the usage help.
  • On reconfigure send SIGHUP.
  • On rotate send SIGQUIT or SIGUSR1.
  • On debug send SIGTRAP or SIGUSR2.
  • On shutdown send SIGTERM.
  • On interrupt send SIGINT.
  • On kill send SIGKILL.
  • On check send 0 / SIGNULL.
  • On parse set global flag to re-parse the config file only.
m
Set global malloc_debug_level to the value given following the option. if none is given it toggles the xmalloc_trace option on/off
n
Set global option opt_signal_service (to true). Stores the additional parameter given in global service_name
r
Set global option opt_remove_service (to TRUE)
l
Stores the syslog facility name in global opt_syslog_facility then performs actions for -s option.
s
Initialize the syslog for output
u
Store the ICP port number given in global option icpPortNumOverride ensuring its a positive number.
v
Display squid version and build information. Then exit.
z
Request cache_dir initialization
–foreground
Set global option opt_foreground
h,?, or unknown

Definition at line 410 of file main.cc.

References add_http_port(), CharacterSet::ALPHA, Debug::BanCacheLogUse(), ConfigFile, Debug::ConfigureSyslog(), DBG_CRITICAL, DBG_IMPORTANT, debugs, CharacterSet::DIGIT, Debug::EnsureDefaultStderrLevel(), fatal(), fatalf(), icpPortNumOverride, SBuf::length(), OPENSSL_VERSION, OpenSSL_version, opt_catch_signals, opt_command_line, opt_create_swap_dirs, opt_foreground, opt_foreground_rebuild, opt_install_service, opt_no_daemon, opt_parse_cfg_only, opt_reload_hit_only, opt_remove_service, opt_reuseaddr, opt_send_signal, opt_signal_service, opt_store_doublecheck, opt_syslog_facility, optForeground, optKid, Debug::override_X, Debug::parseOptions(), port, Debug::ResetStderrLevel(), service_name, sigusr2_handle(), SQUIDSBUFPH, SQUIDSBUFPRINT, TRUE, usage(), version_string, xatoi(), xfree, and xstrdup.

Referenced by SquidMain().

◆ mainInitialize()

static void mainInitialize ( void  )
static

Definition at line 1099 of file main.cc.

References accessLogInit(), authenticateInit(), SquidConfig::chroot_dir, Mem::CleanIdlePools(), SquidConfig::ClientDelay, Config, configured_once, Critical, DBG_CRITICAL, DBG_IMPORTANT, death(), debugs, errorInitialize(), eventAdd(), eventInit(), externalAclInit(), Adaptation::Config::finalize(), ClientDelayConfig::finalize(), Adaptation::Ecap::Config::finalize(), Adaptation::Config::Finalize(), fqdncache_init(), fqdncache_purgelru(), httpHeaderInitModule(), IamPrimaryProcess(), icapLogOpen(), SquidConfig::icp, icpPortNumOverride, Important, DelayPools::Init(), Ssl::Helper::Init(), Ssl::CertValidationHelper::Init(), Dns::Init(), FwdState::initModule(), ipcache_init(), ipcache_purgelru(), SquidConfig::loadable_module_names, LoadableModulesConfigure(), mainSetCwd(), Store::Maintain(), memCheckInit(), mimeInit(), SquidConfig::mimeTablePathname, neighbors_init(), no_suid(), Adaptation::Config::onoff, Security::OpenLogs(), opt_catch_signals, parseEtcHosts(), SquidConfig::Port, ProcessRoles(), reconfigure(), redirectInit(), refreshInit(), AsyncJob::RegisterWithCacheManager(), SBufStatsAction::RegisterWithCacheManager(), rotate_logs(), SA_NODEFER, SA_RESETHAND, SA_RESTART, serverConnectionsOpen(), service_name, setEffectiveUser(), setSystemLimits(), shut_down(), sig_child(), sigusr2_handle(), snmpInit(), Squid_MaxFD, squid_signal(), statInit(), storeInit(), Adaptation::Ecap::TheConfig, Adaptation::Icap::TheConfig, Auth::TheConfig, unlinkdInit(), unlinkdNeeded(), urlInitialize(), version_string, wccp2Init(), wccpInit(), and WIN32_IpAddrChangeMonitorInit().

Referenced by SquidMain().

◆ mainReconfigureFinish()

◆ mainReconfigureStart()

◆ mainRotate()

◆ mainSetCwd()

static void mainSetCwd ( void  )
static

◆ mainStartScript()

static void mainStartScript ( const char *  prog)
static

Definition at line 1755 of file main.cc.

References MAXPATHLEN, squid_start_script, WaitForOnePid(), and xstrncpy().

Referenced by watch_child().

◆ master_revive_kids()

static void master_revive_kids ( int  sig)
static

Definition at line 728 of file main.cc.

References do_revive_kids, master_revive_kids(), and ReviveKidsSignal.

Referenced by master_revive_kids(), and watch_child().

◆ master_shutdown()

static void master_shutdown ( int  sig)
static

Definition at line 742 of file main.cc.

References do_shutdown, master_shutdown(), and ShutdownSignal.

Referenced by master_shutdown(), and watch_child().

◆ masterCheckAndBroadcastSignals()

◆ masterExit()

static void masterExit ( )
static

Definition at line 1884 of file main.cc.

References Kids::allHopeless(), Kids::someSignaled(), and TheKids.

Referenced by watch_child().

◆ masterMaintainKidRevivalSchedule()

static void masterMaintainKidRevivalSchedule ( )
static

Maintains the following invariant: An alarm should be scheduled when and only when there are hopeless kid(s) that cannot be immediately revived.

Definition at line 1848 of file main.cc.

References assert, debugs, Kids::forgetOldFailures(), and TheKids.

Referenced by watch_child().

◆ masterReconfigureFinish()

static void masterReconfigureFinish ( )
static

Definition at line 1808 of file main.cc.

References reconfiguring.

Referenced by masterCheckAndBroadcastSignals().

◆ masterReconfigureStart()

static void masterReconfigureStart ( )
static

◆ masterReviveKids()

static void masterReviveKids ( )
static

◆ masterShutdownStart()

static void masterShutdownStart ( )
static

Definition at line 1785 of file main.cc.

References AvoidSignalAction(), debugs, do_shutdown, and shutting_down.

Referenced by masterCheckAndBroadcastSignals().

◆ masterSignaled()

static bool masterSignaled ( )
inlinestatic

Definition at line 1858 of file main.cc.

References DebugSignal, ReconfigureSignal, ReviveKidsSignal, RotateSignal, and ShutdownSignal.

Referenced by watch_child().

◆ OnTerminate()

static void OnTerminate ( )
static

Definition at line 1302 of file main.cc.

References CurrentExceptionExtra(), DBG_CRITICAL, debugs, and Debug::PrepareToDie().

Referenced by SquidMainSafe().

◆ reconfigure()

◆ RegisterModules()

static void RegisterModules ( )
static

Definition at line 1444 of file main.cc.

References CallRunnerRegistrator, and CallRunnerRegistratorIn.

Referenced by SquidMain().

◆ rotate_logs()

void rotate_logs ( int  sig)

◆ RunConfigUsers()

static void RunConfigUsers ( )
static

◆ sendSignal()

static void sendSignal ( void  )
static

◆ serverConnectionsClose()

◆ serverConnectionsOpen()

◆ setEffectiveUser()

static void setEffectiveUser ( void  )
static

Definition at line 1030 of file main.cc.

References DBG_CRITICAL, debugs, fatal(), keepCapabilities(), and leave_suid().

Referenced by mainInitialize(), mainReconfigureFinish(), and SquidMain().

◆ shut_down()

void shut_down ( int  sig)

◆ sig_child()

void sig_child ( int  sig)

Definition at line 771 of file main.cc.

References do_handle_stopped_child, and sig_child().

Referenced by mainInitialize(), and sig_child().

◆ SquidMain()

int SquidMain ( int  argc,
char **  argv 
)

Definition at line 1487 of file main.cc.

References assert, RegisteredRunner::bootstrapConfig(), SquidConfig::chroot_dir, comm_init(), Config, ConfigFile, ConfigureCurrentKid(), configured_once, CpuAffinityCheck(), CpuAffinityInit(), Store::Controller::create(), current_time, DBG_CRITICAL, debugs, enter_suid(), EventLoop::errcount, failure_notify, fatal_dump(), RegisteredRunner::finalizeConfig(), CommandLine::forEachOption(), getCurrentTime(), EventScheduler::GetInstance(), IamCoordinatorProcess(), IamDiskProcess(), IamMasterProcess(), IamPrimaryProcess(), IamWorkerProcess(), InDaemonMode(), AnyP::UriScheme::Init(), Format::Token::Init(), Fs::Init(), Mem::Init(), Store::Init(), Acl::Init(), Auth::Init(), Ipc::Coordinator::Instance(), leave_suid(), mainHandleCommandLineOption(), mainInitialize(), mainSetCwd(), no_suid(), opt_command_line, opt_create_swap_dirs, opt_foreground, opt_install_service, opt_no_daemon, opt_parse_cfg_only, opt_remove_service, opt_send_signal, parseConfigFile(), Ip::ProbeTransport(), EventLoop::registerEngine(), RegisterModules(), Store::Root(), EventLoop::run(), RunRegisteredHere, sendSignal(), setEffectiveUser(), EventLoop::setPrimaryEngine(), EventLoop::setTimeService(), Debug::SettleStderr(), Debug::SettleSyslog(), setUmask(), DiskIOModule::SetupAllModules(), shortOpStr, Squid_MaxFD, SQUID_MAXFD_LIMIT, squid_start, squidOptions, SquidShutdown(), AsyncJob::Start(), starting_up, StartUsingConfig(), storeFsInit(), Instance::ThrowIfAlreadyRunning(), SquidConfig::umask, UsingSmp(), watch_child(), WIN32_InstallService(), WIN32_RemoveService(), WIN32_SetServiceCommandLine(), WIN32_Subsystem_Init(), WIN32_svcstatusupdate(), Instance::WriteOurPid(), and xstrdup.

Referenced by SquidMainSafe().

◆ SquidMainSafe()

static int SquidMainSafe ( int  argc,
char **  argv 
)
static

Definition at line 1347 of file main.cc.

References CurrentException(), DBG_CRITICAL, debugs, OnTerminate(), and SquidMain().

Referenced by main(), and SquidWinSvcMain().

◆ SquidShutdown()

◆ SquidWinSvcMain()

void WINAPI SquidWinSvcMain ( int  argc,
char **  argv 
)

Definition at line 1324 of file main.cc.

References SquidMainSafe().

◆ StartUsingConfig()

static void StartUsingConfig ( )
static

◆ usage()

static void usage ( void  )
static

Definition at line 325 of file main.cc.

References APP_SHORTNAME, CACHE_HTTP_PORT, and CACHE_ICP_PORT.

Referenced by mainHandleCommandLineOption().

◆ watch_child()

◆ WIN32_svcHandler()

VOID WINAPI WIN32_svcHandler ( DWORD  Opcode)

◆ WIN32_svcstatusupdate()

void WIN32_svcstatusupdate ( DWORD  svcstate,
DWORD  WaitHint 
)

Definition at line 567 of file WinSvc.cc.

References svcHandle, and svcStatus.

Referenced by SignalEngine::doShutdown(), SquidMain(), and SquidShutdown().

Variable Documentation

◆ Chrooted

bool Chrooted = false

Hack: Have we called chroot()? This exposure is needed because some code has to open the same files before and after chroot()

Definition at line 1063 of file main.cc.

Referenced by ConfigureDebugging(), mainSetCwd(), and PidFilenameCalc().

◆ configured_once

int configured_once = 0
static

Definition at line 146 of file main.cc.

Referenced by AvoidSignalAction(), mainInitialize(), SquidMain(), and watch_child().

◆ do_handle_stopped_child

volatile int do_handle_stopped_child = 0
static

Definition at line 155 of file main.cc.

Referenced by SignalEngine::checkEvents(), SignalEngine::handleStoppedChild(), and sig_child().

◆ do_reconfigure

volatile int do_reconfigure = 0
static

◆ do_revive_kids

volatile int do_revive_kids = 0
static

Definition at line 153 of file main.cc.

Referenced by master_revive_kids(), masterCheckAndBroadcastSignals(), and masterReviveKids().

◆ do_rotate

volatile int do_rotate = 0
static

Definition at line 151 of file main.cc.

Referenced by SignalEngine::checkEvents(), mainRotate(), and rotate_logs().

◆ do_shutdown

◆ icpPortNumOverride

int icpPortNumOverride = 1
static

Definition at line 145 of file main.cc.

Referenced by mainHandleCommandLineOption(), and mainInitialize().

◆ opt_command_line

int opt_command_line = FALSE
static

Definition at line 138 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

◆ opt_install_service

int opt_install_service = FALSE
static

Definition at line 136 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

◆ opt_remove_service

int opt_remove_service = FALSE
static

Definition at line 137 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

◆ opt_signal_service

int opt_signal_service = FALSE
static

Definition at line 143 of file main.cc.

Referenced by mainHandleCommandLineOption(), and sendSignal().

◆ opt_syslog_facility

char* opt_syslog_facility = nullptr
static

Definition at line 144 of file main.cc.

Referenced by mainHandleCommandLineOption().

◆ ReconfigureSignal

int ReconfigureSignal = -1
static

Definition at line 158 of file main.cc.

Referenced by masterCheckAndBroadcastSignals(), masterSignaled(), and reconfigure().

◆ ReviveKidsSignal

int ReviveKidsSignal = -1
static

Definition at line 160 of file main.cc.

Referenced by master_revive_kids(), masterCheckAndBroadcastSignals(), and masterSignaled().

◆ RotateSignal

int RotateSignal = -1
static

Definition at line 157 of file main.cc.

Referenced by masterCheckAndBroadcastSignals(), masterSignaled(), and rotate_logs().

◆ shortOpStr

const char* shortOpStr
static
Initial value:
=
"O:Vir"
"CDFNRSYXa:d:f:hk:m::n:sl:u:vz?"

Definition at line 393 of file main.cc.

Referenced by main(), Ping::TheConfig::parseCommandOpts(), Transport::TheConfig::parseCommandOpts(), and SquidMain().

◆ shutdown_status

volatile int shutdown_status = EXIT_SUCCESS
static

Definition at line 154 of file main.cc.

Referenced by shut_down(), and SquidShutdown().

◆ ShutdownSignal

int ShutdownSignal = -1
static

◆ squid_start_script

const char* squid_start_script = "squid_start"
static

Definition at line 177 of file main.cc.

Referenced by mainStartScript().

◆ squidOptions

struct option squidOptions[]
static
Initial value:
= {
{"foreground", no_argument, nullptr, optForeground},
{"kid", required_argument, nullptr, optKid},
{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'v'},
{nullptr, 0, nullptr, 0}
}
@ optKid
Definition: main.cc:387
@ optForeground
Definition: main.cc:386

Definition at line 400 of file main.cc.

Referenced by SquidMain().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors