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 "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.


class  StoreRootEngine
class  SignalEngine


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


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 ()


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

Definition at line 412 of file

Function Documentation

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

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

Definition at line 259 of file

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

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

static void GoIntoBackground ( )

Definition at line 1858 of file

References pid, and xstrerr().

Referenced by watch_child().

int main ( int  argc,
char **  argv 

Definition at line 1386 of file

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

static bool mainChangeDir ( const char *  dir)

Definition at line 1084 of file

References DBG_CRITICAL, debugs, and xstrerr().

Referenced by mainSetCwd().

static void mainHandleCommandLineOption ( const int  optId,
const char *  optValue 
Unset/disabel global option for catchign signals. opt_catch_signals
OBSOLETE: WAS: override to prevent optional startup DNS tests.
Set global option for foreground rebuild. opt_foreground_rebuild
Set global option for 'no_daemon' mode. opt_no_daemon
Set global option. opt_command_lin and WIN32_Command_Line
Unset/disable global option opt_reuseaddr
Set global option opt_store_doublecheck
Force full debugging
Set global option opt_reload_hit_only
Set global option opt_install_service (to TRUE)
Add optional HTTP port as given following the option
Set global option Debug::log_stderr to the number given following the option
Load the file given instead of the default squid.conf.
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.
Set global malloc_debug_level to the value given following the option. if none is given it toggles the xmalloc_trace option on/off
Set global option opt_signal_service (to true). Stores the additional parameter given in global service_name
Set global option opt_remove_service (to TRUE)
Stores the syslog facility name in global opt_syslog_facility then performs actions for -s option.
Initialize the syslog for output
Store the ICP port number given in global option icpPortNumOverride ensuring its a positive number.
Display squid version and build information. Then exit.
Set global option Debug::log_stderr and opt_create_swap_dirs
Set global option opt_foreground
h,?, or unknown

Definition at line 440 of file

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  )

Definition at line 1133 of file

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 void mainStartScript ( const char *  prog)

Definition at line 1747 of file

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

Referenced by watch_child().

void master_revive_kids ( int  sig)

Definition at line 754 of file

References do_revive_kids, and ReviveKidsSignal.

Referenced by watch_child().

void master_shutdown ( int  sig)

Definition at line 768 of file

References do_shutdown, and ShutdownSignal.

Referenced by watch_child().

static void masterExit ( )

Definition at line 1873 of file

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

Referenced by watch_child().

static void masterMaintainKidRevivalSchedule ( )

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 1840 of file

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

Referenced by watch_child().

static void masterReconfigureFinish ( )

Definition at line 1800 of file

References reconfiguring.

Referenced by masterCheckAndBroadcastSignals().

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

Definition at line 1777 of file

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

Referenced by masterCheckAndBroadcastSignals().

static bool masterSignaled ( )

Definition at line 1850 of file

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

Referenced by watch_child().

static void OnTerminate ( )

Definition at line 1359 of file

References CurrentException(), DBG_CRITICAL, and debugs.

Referenced by SquidMainSafe().

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

Definition at line 1064 of file

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 799 of file

References do_handle_stopped_child, and sig_child().

Referenced by mainInitialize(), and sig_child().

int SquidMain ( int  argc,
char **  argv 

Definition at line 1451 of file

References assert, 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(), 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 

Definition at line 1402 of file

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

Referenced by main(), and SquidWinSvcMain().

void WINAPI SquidWinSvcMain ( int  argc,
char **  argv 

Definition at line 1379 of file

References SquidMainSafe().

static void StartUsingConfig ( )
static void usage ( void  )

Definition at line 356 of file


Referenced by mainHandleCommandLineOption().

VOID WINAPI WIN32_svcHandler ( DWORD  Opcode)
void WIN32_svcstatusupdate ( DWORD  svcstate,
DWORD  WaitHint 

Definition at line 567 of file

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 1097 of file

Referenced by PidFilenameCalc().

int configured_once = 0

Definition at line 150 of file

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

volatile int do_handle_stopped_child = 0

Definition at line 159 of file

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

volatile int do_reconfigure = 0
volatile int do_revive_kids = 0

Definition at line 157 of file

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

volatile int do_rotate = 0

Definition at line 155 of file

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

int icpPortNumOverride = 1

Definition at line 149 of file

Referenced by mainHandleCommandLineOption(), and mainInitialize().

int opt_command_line = FALSE

Definition at line 142 of file

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_install_service = FALSE

Definition at line 140 of file

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_remove_service = FALSE

Definition at line 141 of file

Referenced by mainHandleCommandLineOption(), and SquidMain().

int opt_signal_service = FALSE

Definition at line 147 of file

Referenced by mainHandleCommandLineOption(), and sendSignal().

char* opt_syslog_facility = NULL

Definition at line 148 of file

Referenced by mainHandleCommandLineOption().

int ReconfigureSignal = -1

Definition at line 162 of file

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

int ReviveKidsSignal = -1

Definition at line 164 of file

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

int RotateSignal = -1

Definition at line 161 of file

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

const char* shortOpStr
Initial value:

Definition at line 423 of file

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

volatile int shutdown_status = EXIT_SUCCESS

Definition at line 158 of file

Referenced by shut_down(), and SquidShutdown().

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

Definition at line 181 of file

Referenced by mainStartScript().

struct option squidOptions[]
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 at line 430 of file






Web Site Translations