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 "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 "ident/Ident.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 "profiler/Profiler.h"
#include "redirect.h"
#include "refresh.h"
#include "sbuf/Stream.h"
#include "SBufStatsAction.h"
#include "send-announce.h"
#include "SquidConfig.h"
#include "SquidTime.h"
#include "stat.h"
#include "StatCounters.h"
#include "Store.h"
#include "store/Disks.h"
#include "store_log.h"
#include "StoreFileSystem.h"
#include "tools.h"
#include "unlinkd.h"
#include "URL.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 "esi/Module.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)
 
void master_revive_kids (int sig)
 
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 StartUsingConfig ()
 
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 = NULL
 
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
Enumerator
optForeground 
optKid 

Definition at line 413 of file main.cc.

Function Documentation

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 260 of file main.cc.

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

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

static void GoIntoBackground ( )
static

Definition at line 1859 of file main.cc.

References pid, and xstrerr().

Referenced by watch_child().

int main ( int  argc,
char **  argv 
)

Definition at line 1387 of file main.cc.

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

static bool mainChangeDir ( const char *  dir)
static

Definition at line 1085 of file main.cc.

References DBG_CRITICAL, debugs, and xstrerr().

Referenced by mainSetCwd().

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
Set global option Debug::log_stderr to the number given following the option
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
Set global option Debug::log_stderr and opt_create_swap_dirs
–foreground
Set global option opt_foreground
h,?, or unknown

Definition at line 441 of file main.cc.

References _db_set_syslog(), add_http_port(), CharacterSet::ALPHA, Parser::Tokenizer::atEnd(), ConfigFile, DBG_CRITICAL, debugs, CharacterSet::DIGIT, fatal(), fatalf(), icpPortNumOverride, SBuf::length(), Debug::log_stderr, 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, Parser::Tokenizer::prefix(), service_name, sigusr2_handle(), SQUIDSBUFPH, SQUIDSBUFPRINT, TRUE, usage(), version_string, xatoi(), xfree, and xstrdup.

Referenced by SquidMain().

static void mainInitialize ( void  )
static

Definition at line 1134 of file main.cc.

References _db_init(), accessLogInit(), SquidConfig::announce, authenticateInit(), Debug::cache_log, cbdataRegisterWithCacheManager(), SquidConfig::chroot_dir, Mem::CleanIdlePools(), SquidConfig::ClientDelay, Config, configured_once, DBG_CRITICAL, DBG_IMPORTANT, death(), debug_log, Debug::debugOptions, debugs, errorInitialize(), eventAdd(), eventInit(), externalAclInit(), FD_LOG, fd_open(), Adaptation::Config::Finalize(), Adaptation::Ecap::Config::finalize(), ClientDelayConfig::finalize(), Adaptation::Config::finalize(), fqdncache_init(), fqdncache_purgelru(), httpHeaderInitModule(), IamPrimaryProcess(), icapLogOpen(), SquidConfig::icp, icpPortNumOverride, Esi::Init(), Dns::Init(), Ssl::Helper::Init(), Ident::Init(), DelayPools::Init(), Ssl::CertValidationHelper::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, SquidConfig::onoff, opt_catch_signals, parseEtcHosts(), SquidConfig::Port, ProcessRoles(), reconfigure(), redirectInit(), refreshInit(), 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(), start_announce(), statInit(), storeInit(), Auth::TheConfig, Adaptation::Icap::TheConfig, Adaptation::Ecap::TheConfig, unlinkdInit(), unlinkdNeeded(), urlInitialize(), version_string, wccp2Init(), wccpInit(), WIN32_IpAddrChangeMonitorInit(), and xprof_event().

Referenced by SquidMain().

static void mainSetCwd ( void  )
static
static void mainStartScript ( const char *  prog)
static

Definition at line 1748 of file main.cc.

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

Referenced by watch_child().

void master_revive_kids ( int  sig)

Definition at line 755 of file main.cc.

References do_revive_kids, and ReviveKidsSignal.

Referenced by watch_child().

void master_shutdown ( int  sig)

Definition at line 769 of file main.cc.

References do_shutdown, and ShutdownSignal.

Referenced by watch_child().

static void masterExit ( )
static

Definition at line 1874 of file main.cc.

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

Referenced by watch_child().

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 1841 of file main.cc.

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

Referenced by watch_child().

static void masterReconfigureFinish ( )
static

Definition at line 1801 of file main.cc.

References reconfiguring.

Referenced by masterCheckAndBroadcastSignals().

static void masterReconfigureStart ( )
static
static void masterReviveKids ( )
static
static void masterShutdownStart ( )
static

Definition at line 1778 of file main.cc.

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

Referenced by masterCheckAndBroadcastSignals().

static bool masterSignaled ( )
inlinestatic

Definition at line 1851 of file main.cc.

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

Referenced by watch_child().

static void OnTerminate ( )
static

Definition at line 1360 of file main.cc.

References CurrentException(), DBG_CRITICAL, and debugs.

Referenced by SquidMainSafe().

void rotate_logs ( int  sig)
static void sendSignal ( void  )
static
static void setEffectiveUser ( void  )
static

Definition at line 1065 of file main.cc.

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

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

void shut_down ( int  sig)
void sig_child ( int  sig)

Definition at line 800 of file main.cc.

References do_handle_stopped_child, and sig_child().

Referenced by mainInitialize(), and sig_child().

int SquidMain ( int  argc,
char **  argv 
)

Definition at line 1452 of file main.cc.

References assert, SquidConfig::chroot_dir, comm_init(), Config, ConfigFile, ConfigureCurrentKid(), configured_once, CpuAffinityCheck(), CpuAffinityInit(), Store::Controller::create(), current_time, DBG_CRITICAL, debugs, DefaultConfigFile, enter_suid(), EventLoop::errcount, failure_notify, fatal_dump(), FD_LOG, fd_open(), RegisteredRunner::finalizeConfig(), CommandLine::forEachOption(), getCurrentTime(), EventScheduler::GetInstance(), IamCoordinatorProcess(), IamDiskProcess(), IamMasterProcess(), IamPrimaryProcess(), IamWorkerProcess(), InDaemonMode(), Fs::Init(), Auth::Init(), Mem::Init(), Acl::Init(), Format::Token::Init(), AnyP::UriScheme::Init(), Store::Init(), Ipc::Coordinator::Instance(), leave_suid(), mainHandleCommandLineOption(), mainInitialize(), mainSetCwd(), no_suid(), NULL, 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(), Debug::parseOptions(), Ip::ProbeTransport(), EventLoop::registerEngine(), Mem::Report(), Store::Root(), EventLoop::run(), RunRegisteredHere, sendSignal(), setEffectiveUser(), setMaxFD(), EventLoop::setPrimaryEngine(), EventLoop::setTimeService(), setUmask(), StoreFileSystem::SetupAllFs(), DiskIOModule::SetupAllModules(), Squid_MaxFD, SQUID_MAXFD_LIMIT, squid_start, 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().

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

Definition at line 1403 of file main.cc.

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

Referenced by main(), and SquidWinSvcMain().

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

Definition at line 1380 of file main.cc.

References SquidMainSafe().

static void StartUsingConfig ( )
static
static void usage ( void  )
static

Definition at line 357 of file main.cc.

References APP_SHORTNAME, CACHE_HTTP_PORT, CACHE_ICP_PORT, and DefaultConfigFile.

Referenced by mainHandleCommandLineOption().

VOID WINAPI WIN32_svcHandler ( DWORD  Opcode)
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

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 1098 of file main.cc.

Referenced by PidFilenameCalc().

int configured_once = 0
static

Definition at line 151 of file main.cc.

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

volatile int do_handle_stopped_child = 0
static

Definition at line 160 of file main.cc.

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

volatile int do_reconfigure = 0
static
volatile int do_revive_kids = 0
static

Definition at line 158 of file main.cc.

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

volatile int do_rotate = 0
static

Definition at line 156 of file main.cc.

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

int icpPortNumOverride = 1
static

Definition at line 150 of file main.cc.

Referenced by mainHandleCommandLineOption(), and mainInitialize().

int opt_command_line = FALSE
static

Definition at line 143 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_install_service = FALSE
static

Definition at line 141 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_remove_service = FALSE
static

Definition at line 142 of file main.cc.

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_signal_service = FALSE
static

Definition at line 148 of file main.cc.

Referenced by mainHandleCommandLineOption(), and sendSignal().

char* opt_syslog_facility = NULL
static

Definition at line 149 of file main.cc.

Referenced by mainHandleCommandLineOption().

int ReconfigureSignal = -1
static

Definition at line 163 of file main.cc.

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

int ReviveKidsSignal = -1
static

Definition at line 165 of file main.cc.

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

int RotateSignal = -1
static

Definition at line 162 of file main.cc.

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

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

Definition at line 424 of file main.cc.

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

volatile int shutdown_status = EXIT_SUCCESS
static

Definition at line 159 of file main.cc.

Referenced by shut_down(), and SquidShutdown().

int ShutdownSignal = -1
static
const char* squid_start_script = "squid_start"
static

Definition at line 182 of file main.cc.

Referenced by mainStartScript().

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

Definition at line 431 of file main.cc.

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors