\File{main.c},{11:44},{Feb  6 1997}
\L{\LB{\C{}\/*}}
\L{\LB{ * \$Id: main.c,v 1.3 1997\/01\/08 04:56:46 marthag Exp \$}}
\L{\LB{ *}}
\L{\LB{ * DEBUG: section 1     Startup and Main Loop}}
\L{\LB{ * AUTHOR: Harvest Derived}}
\L{\LB{ *}}
\L{\LB{ * SQUID Internet Object Cache  http:\/\/squid.nlanr.net\/Squid\/}}
\L{\LB{ * \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-}}
\L{\LB{ *}}
\L{\LB{ *  Squid is the result of efforts by numerous individuals from the}}
\L{\LB{ *  Internet community.  Development is led by Duane Wessels of the}}
\L{\LB{ *  National Laboratory for Applied Network Research and funded by}}
\L{\LB{ *  the National Science Foundation.}}
\L{\LB{ *}}
\L{\LB{ *  This program is free software; you can redistribute it and\/or modify}}
\L{\LB{ *  it under the terms of the GNU General Public License as published by}}
\L{\LB{ *  the Free Software Foundation; either version 2 of the License, or}}
\L{\LB{ *  (at your option) any later version.}}
\L{\LB{ *  }}
\L{\LB{ *  This program is distributed in the hope that it will be useful,}}
\L{\LB{ *  but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\L{\LB{ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\L{\LB{ *  GNU General Public License for more details.}}
\L{\LB{ *  }}
\L{\LB{ *  You should have received a copy of the GNU General Public License}}
\L{\LB{ *  along with this program; if not, write to the Free Software}}
\L{\LB{ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\L{\LB{ *  }}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/*}}
\L{\LB{ * Copyright (c) 1994, 1995.  All rights reserved.}}
\L{\LB{ *  }}
\L{\LB{ *   The Harvest software was developed by the Internet Research Task}}
\L{\LB{ *   Force Research Group on Resource Discovery (IRTF\-RD):}}
\L{\LB{ *  }}
\L{\LB{ *         Mic Bowman of Transarc Corporation.}}
\L{\LB{ *         Peter Danzig of the University of Southern California.}}
\L{\LB{ *         Darren R. Hardy of the University of Colorado at Boulder.}}
\L{\LB{ *         Udi Manber of the University of Arizona.}}
\L{\LB{ *         Michael F. Schwartz of the University of Colorado at Boulder.}}
\L{\LB{ *         Duane Wessels of the University of Colorado at Boulder.}}
\L{\LB{ *  }}
\L{\LB{ *   This copyright notice applies to software in the Harvest}}
\L{\LB{ *   ``src\/\'\' directory only.  Users should consult the individual}}
\L{\LB{ *   copyright notices in the ``components\/\'\' subdirectories for}}
\L{\LB{ *   copyright information about other software bundled with the}}
\L{\LB{ *   Harvest source code distribution.}}
\L{\LB{ *  }}
\L{\LB{ * TERMS OF USE}}
\L{\LB{ *   }}
\L{\LB{ *   The Harvest software may be used and re\-distributed without}}
\L{\LB{ *   charge, provided that the software origin and research team are}}
\L{\LB{ *   cited in any use of the system.  Most commonly this is}}
\L{\LB{ *   accomplished by including a link to the Harvest Home Page}}
\L{\LB{ *   (http:\/\/harvest.cs.colorado.edu\/) from the query page of any}}
\L{\LB{ *   Broker you deploy, as well as in the query result pages.  These}}
\L{\LB{ *   links are generated automatically by the standard Broker}}
\L{\LB{ *   software distribution.}}
\L{\LB{ *   }}
\L{\LB{ *   The Harvest software is provided ``as is\'\', without express or}}
\L{\LB{ *   implied warranty, and with no support nor obligation to assist}}
\L{\LB{ *   in its use, correction, modification or enhancement.  We assume}}
\L{\LB{ *   no liability with respect to the infringement of copyrights,}}
\L{\LB{ *   trade secrets, or any patents, and are not responsible for}}
\L{\LB{ *   consequential damages.  Proper use of the Harvest software is}}
\L{\LB{ *   entirely the responsibility of the user.}}
\L{\LB{ *  }}
\L{\LB{ * DERIVATIVE WORKS}}
\L{\LB{ *  }}
\L{\LB{ *   Users may make derivative works from the Harvest software, subject }}
\L{\LB{ *   to the following constraints:}}
\L{\LB{ *  }}
\L{\LB{ *     \- You must include the above copyright notice and these }}
\L{\LB{ *       accompanying paragraphs in all forms of derivative works, }}
\L{\LB{ *       and any documentation and other materials related to such }}
\L{\LB{ *       distribution and use acknowledge that the software was }}
\L{\LB{ *       developed at the above institutions.}}
\L{\LB{ *  }}
\L{\LB{ *     \- You must notify IRTF\-RD regarding your distribution of }}
\L{\LB{ *       the derivative work.}}
\L{\LB{ *  }}
\L{\LB{ *     \- You must clearly notify users that your are distributing }}
\L{\LB{ *       a modified version and not the original Harvest software.}}
\L{\LB{ *  }}
\L{\LB{ *     \- Any derivative product is also subject to these copyright }}
\L{\LB{ *       and use restrictions.}}
\L{\LB{ *  }}
\L{\LB{ *   Note that the Harvest software is NOT in the public domain.  We}}
\L{\LB{ *   retain copyright, as specified above.}}
\L{\LB{ *  }}
\L{\LB{ * HISTORY OF FREE SOFTWARE STATUS}}
\L{\LB{ *  }}
\L{\LB{ *   Originally we required sites to license the software in cases}}
\L{\LB{ *   where they were going to build commercial products\/services}}
\L{\LB{ *   around Harvest.  In June 1995 we changed this policy.  We now}}
\L{\LB{ *   allow people to use the core Harvest software (the code found in}}
\L{\LB{ *   the Harvest ``src\/\'\' directory) for free.  We made this change}}
\L{\LB{ *   in the interest of encouraging the widest possible deployment of}}
\L{\LB{ *   the technology.  The Harvest software is really a reference}}
\L{\LB{ *   implementation of a set of protocols and formats, some of which}}
\L{\LB{ *   we intend to standardize.  We encourage commercial}}
\L{\LB{ *   re\-implementations of code complying to this set of standards.  }}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#include} \S{}\"squid.h\"\SE{}}}
\L{\LB{}}
\L{\LB{time\_t squid\_starttime = 0;}}
\L{\LB{\K{int} theHttpConnection = \-1;}}
\L{\LB{\K{int} theInIcpConnection = \-1;}}
\L{\LB{\K{int} theOutIcpConnection = \-1;}}
\L{\LB{\K{int} vizSock = \-1;}}
\L{\LB{\K{int} do\_reuse = 1;}}
\L{\LB{\K{int} opt\_unlink\_on\_reload = 0;}}
\L{\LB{\K{int} opt\_reload\_hit\_only = 0;}\Tab{32}{\C{}\/* only UDP\_HIT during store relaod *\/\CE{}}}
\L{\LB{\K{int} opt\_catch\_signals = 1;}}
\L{\LB{\K{int} opt\_dns\_tests = 1;}}
\L{\LB{\K{int} opt\_foreground\_rebuild = 0;}}
\L{\LB{\K{int} opt\_zap\_disk\_store = 0;}}
\L{\LB{\K{int} opt\_syslog\_enable = 0;}\Tab{32}{\C{}\/* disabled by default *\/\CE{}}}
\L{\LB{\K{int} opt\_no\_ipcache = 0;}\Tab{32}{\C{}\/* use ipcache by default *\/\CE{}}}
\L{\LB{\K{static} \K{int} opt\_send\_signal = \-1;}\Tab{40}{\C{}\/* no signal to send *\/\CE{}}}
\L{\LB{\K{int} opt\_udp\_hit\_obj = 0;}\Tab{32}{\C{}\/* ask for HIT\_OBJ\'s *\/\CE{}}}
\L{\LB{\K{int} opt\_mem\_pools = 1;}}
\L{\LB{\K{int} opt\_forwarded\_for = 1;}}
\L{\LB{\K{int} opt\_accel\_uses\_host = 0;}}
\L{\LB{\C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{\K{int} opt\_dynamic\_hierarchy = 0;   \C{}\/* by default, don\'t use dynamic hierarchy *\/\CE{}}}
\L{\LB{\K{int} num\_hosts = 0;}}
\L{\LB{\K{struct} hostinfo *tablePtr  = NULL;}}
\L{\LB{\C{}\/* global variable that points to the list of machines in the unit interval *\/\CE{}}}
\L{\LB{\K{struct} machplace *uiPtr = NULL;}}
\L{\LB{const \K{char} *myhostname;}}
\L{\LB{\C{}\/* end DH changes *\/\CE{}}\Tab{24}{    }}
\L{\LB{\K{int} vhost\_mode = 0;}}
\L{\LB{volatile \K{int} unbuffered\_logs = 1;}\Tab{40}{\C{}\/* debug and hierarchy unbuffered by default *\/\CE{}}}
\L{\LB{volatile \K{int} shutdown\_pending = 0;}\Tab{40}{\C{}\/* set by SIGTERM handler (shut\_down()) *\/\CE{}}}
\L{\LB{volatile \K{int} reread\_pending = 0;}\Tab{40}{\C{}\/* set by SIGHUP handler *\/\CE{}}}
\L{\LB{const \K{char} *const version\_string = SQUID\_VERSION;}}
\L{\LB{const \K{char} *const appname = \S{}\"squid\"\SE{};}}
\L{\LB{const \K{char} *const localhost = \S{}\"127.0.0.1\"\SE{};}}
\L{\LB{\K{struct} in\_addr local\_addr;}}
\L{\LB{\K{struct} in\_addr no\_addr;}}
\L{\LB{\K{struct} in\_addr any\_addr;}}
\L{\LB{\K{struct} in\_addr theOutICPAddr;}}
\L{\LB{const \K{char} *const dash\_str = \S{}\"\-\"\SE{};}}
\L{\LB{const \K{char} *const null\_string = \S{}\"\"\SE{};}}
\L{\LB{\K{char} ThisCache[SQUIDHOSTNAMELEN \<\< 1];}}
\L{\LB{\K{unsigned} \K{int} inaddr\_none;}}
\L{\LB{}}
\L{\LB{\C{}\/* for error reporting from xmalloc and friends *\/\CE{}}}
\L{\LB{\K{extern} \K{void} (*failure\_notify) \_PARAMS((const \K{char} *));}}
\L{\LB{}}
\L{\LB{\K{static} volatile \K{int} rotate\_pending = 0;}\Tab{48}{\C{}\/* set by SIGUSR1 handler *\/\CE{}}}
\L{\LB{\K{static} \K{int} httpPortNumOverride = 1;}}
\L{\LB{\K{static} \K{int} icpPortNumOverride = 1;}\Tab{40}{\C{}\/* Want to detect \"\-u 0\" *\/\CE{}}}
\L{\LB{\K{\#if} MALLOC\_DBG}}
\L{\LB{\K{static} \K{int} malloc\_debug\_level = 0;}}
\L{\LB{\K{\#endif}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void} rotate\_logs \_PARAMS((\K{int}));}}
\L{\LB{\K{static} \K{void} reconfigure \_PARAMS((\K{int}));}}
\L{\LB{\K{static} \K{void} mainInitialize \_PARAMS((\K{void}));}}
\L{\LB{\K{static} \K{void} mainReinitialize \_PARAMS((\K{void}));}}
\L{\LB{\K{static} \K{void} usage \_PARAMS((\K{void}));}}
\L{\LB{\K{static} \K{void} mainParseOptions \_PARAMS((\K{int}, \K{char} **));}}
\L{\LB{\K{static} \K{void} sendSignal \_PARAMS((\K{void}));}}
\L{\LB{\K{static} \K{void} serverConnectionsOpen \_PARAMS((\K{void}));}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{usage}usage(\K{void})}}
\L{\LB{\{}}
\L{\LB{    fprintf(stderr,}}
\L{\LB{}\Tab{8}{    \C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{}\Tab{8}{    \S{}\"Usage: \%s [\-dhsvzCDFRUVY] [\-f config\-file] [\-[au] port] [\-k signal]\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-a port   Specify ASCII port number (default: \%d).\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-d        Use dynamic hierarchy.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{    \C{}\/* end DH changes *\/\CE{}}\Tab{40}{    }}
\L{\LB{}\Tab{8}{\S{}\"       \-f file   Use given config\-file instead of\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"                 \%s\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-h        Print help message.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-i        Disable IP caching.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-k reconfigure\|rotate\|shutdown\|interrupt\|kill\|debug\|check\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"                 Send signal to running copy and exit.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-s        Enable logging to syslog.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-u port   Specify ICP port number (default: \%d), disable with 0.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-v        Print version.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-z        Zap disk storage \-\- deletes all objects in disk cache.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-C        Do not catch fatal signals.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-D        Disable initial DNS tests.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-F        Foreground fast store rebuild.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-R        Do not set REUSEADDR on port.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-U        Unlink expired objects on reload.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-V        Virtual host httpd\-accelerator.\!n\"\SE{}}}
\L{\LB{}\Tab{8}{\S{}\"       \-Y        Only return UDP\_HIT or UDP\_RELOADING during fast reload.\!n\"\SE{},}}
\L{\LB{}\Tab{8}{appname, CACHE\_HTTP\_PORT, DefaultConfigFile, CACHE\_ICP\_PORT);}}
\L{\LB{    exit(1);}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{mainParseOptions}mainParseOptions(\K{int} argc, \K{char} *argv[])}}
\L{\LB{\{}}
\L{\LB{    \K{extern} \K{char} *optarg;}}
\L{\LB{    \K{int} c;}}
\L{\LB{}}
\L{\LB{    \C{}\/* begin DH changes *\/\CE{}}\Tab{32}{    }}
\L{\LB{    \K{while} ((c = getopt(argc, argv, \S{}\"CDFRUVYa:bdf:hik:m:su:vz?\"\SE{})) != \-1) \{}}
\L{\LB{      \C{}\/* end DH changes *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{switch} (c) \{}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'C\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_catch\_signals = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'D\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_dns\_tests = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'F\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_foreground\_rebuild = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'R\'\SE{}:}}
\L{\LB{}\Tab{8}{    do\_reuse = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'U\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_unlink\_on\_reload = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'V\'\SE{}:}}
\L{\LB{}\Tab{8}{    vhost\_mode = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'Y\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_reload\_hit\_only = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'a\'\SE{}:}}
\L{\LB{}\Tab{8}{    httpPortNumOverride = atoi(optarg);}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'b\'\SE{}:}}
\L{\LB{}\Tab{8}{    unbuffered\_logs = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{    \C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'d\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_dynamic\_hierarchy = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\C{}\/* end DH changes *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'f\'\SE{}:}}
\L{\LB{}\Tab{8}{    xfree(ConfigFile);}}
\L{\LB{}\Tab{8}{    ConfigFile = xstrdup(optarg);}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'h\'\SE{}:}}
\L{\LB{}\Tab{8}{    usage();}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'i\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_no\_ipcache = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'k\'\SE{}:}}
\L{\LB{}\Tab{8}{    \K{if} ((\K{int}) strlen(optarg) \< 1)}}
\L{\LB{}\Tab{16}{usage();}}
\L{\LB{}\Tab{8}{    \K{if} (!strncmp(optarg, \S{}\"reconfigure\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGHUP;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"rotate\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGUSR1;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"debug\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGUSR2;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"shutdown\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGTERM;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"interrupt\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGINT;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"kill\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = SIGKILL;}}
\L{\LB{}\Tab{8}{    \K{else} \K{if} (!strncmp(optarg, \S{}\"check\"\SE{}, strlen(optarg)))}}
\L{\LB{}\Tab{16}{opt\_send\_signal = 0;}\Tab{40}{\C{}\/* SIGNULL *\/\CE{}}}
\L{\LB{}\Tab{8}{    \K{else}}}
\L{\LB{}\Tab{16}{usage();}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'m\'\SE{}:}}
\L{\LB{\K{\#if} MALLOC\_DBG}}
\L{\LB{}\Tab{8}{    malloc\_debug\_level = atoi(optarg);}}
\L{\LB{}\Tab{8}{    \C{}\/* NOTREACHED *\/\CE{}}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{\K{\#else}}}
\L{\LB{}\Tab{8}{    fatal(\S{}\"Need to add \-DMALLOC\_DBG when compiling to use \-m option\"\SE{});}}
\L{\LB{}\Tab{8}{    \C{}\/* NOTREACHED *\/\CE{}}}
\L{\LB{\K{\#endif}}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'s\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_syslog\_enable = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'u\'\SE{}:}}
\L{\LB{}\Tab{8}{    icpPortNumOverride = atoi(optarg);}}
\L{\LB{}\Tab{8}{    \K{if} (icpPortNumOverride \< 0)}}
\L{\LB{}\Tab{16}{icpPortNumOverride = 0;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'v\'\SE{}:}}
\L{\LB{}\Tab{8}{    printf(\S{}\"Squid Cache: Version \%s\!n\"\SE{}, version\_string);}}
\L{\LB{}\Tab{8}{    exit(0);}}
\L{\LB{}\Tab{8}{    \C{}\/* NOTREACHED *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'z\'\SE{}:}}
\L{\LB{}\Tab{8}{    opt\_zap\_disk\_store = 1;}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\K{case} \S{}\'?\'\SE{}:}}
\L{\LB{}\Tab{8}{\K{default}:}}
\L{\LB{}\Tab{8}{    usage();}}
\L{\LB{}\Tab{8}{    \K{break};}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{    \}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{rotate\_logs}rotate\_logs(\K{int} sig)}}
\L{\LB{\{}}
\L{\LB{    debug(1, 1, \S{}\"rotate\_logs: SIGUSR1 received.\!n\"\SE{});}}
\L{\LB{    rotate\_pending = 1;}}
\L{\LB{\K{\#if} !HAVE\_SIGACTION}}
\L{\LB{    signal(sig, rotate\_logs);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{reconfigure}reconfigure(\K{int} sig)}}
\L{\LB{\{}}
\L{\LB{    debug(1, 1, \S{}\"reconfigure: SIGHUP received\!n\"\SE{});}}
\L{\LB{    debug(1, 1, \S{}\"Waiting \%d seconds for active connections to finish\!n\"\SE{},}}
\L{\LB{}\Tab{8}{Config.lifetimeShutdown);}}
\L{\LB{    reread\_pending = 1;}}
\L{\LB{\K{\#if} !HAVE\_SIGACTION}}
\L{\LB{    signal(sig, reconfigure);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{void}}}
\L{\LB{\Proc{shut\_down}shut\_down(\K{int} sig)}}
\L{\LB{\{}}
\L{\LB{    shutdown\_pending = sig == SIGINT ? \-1 : 1;}}
\L{\LB{    debug(1, 1, \S{}\"Preparing for shutdown after \%d connections\!n\"\SE{},}}
\L{\LB{}\Tab{8}{ntcpconn + nudpconn);}}
\L{\LB{    \K{if} (opt\_dynamic\_hierarchy) \{}}
\L{\LB{      \C{}\/* remove self from the network *\/\CE{}}}
\L{\LB{      delself();}}
\L{\LB{      \K{if} ((dump()) != 0) \{}}
\L{\LB{}\Tab{8}{debug(1,1,\S{}\"Error in dumping network status, data may be lost.\!n\"\SE{});}}
\L{\LB{      \}}}
\L{\LB{    \}}}
\L{\LB{    debug(1, 1, \S{}\"Waiting \%d seconds for active connections to finish\!n\"\SE{},}}
\L{\LB{}\Tab{8}{shutdown\_pending \> 0 ? Config.lifetimeShutdown : 0);}}
\L{\LB{\K{\#ifdef} KILL\_PARENT\_OPT}}
\L{\LB{    debug(1, 1, \S{}\"Killing RunCache, pid \%d\!n\"\SE{}, getppid());}}
\L{\LB{    kill(getppid(), sig);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\K{\#if} SA\_RESETHAND == 0}}
\L{\LB{    signal(SIGTERM, SIG\_DFL);}}
\L{\LB{    signal(SIGINT, SIG\_DFL);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{serverConnectionsOpen}serverConnectionsOpen(\K{void})}}
\L{\LB{\{}}
\L{\LB{    \K{struct} in\_addr addr;}}
\L{\LB{    \K{struct} sockaddr\_in xaddr;}}
\L{\LB{    u\_short port;}}
\L{\LB{    \K{int} len;}}
\L{\LB{    \K{int} x;}}
\L{\LB{    enter\_suid();}}
\L{\LB{    theHttpConnection = comm\_open(SOCK\_STREAM,}}
\L{\LB{}\Tab{8}{0,}}
\L{\LB{}\Tab{8}{Config.Addrs.tcp\_incoming,}}
\L{\LB{}\Tab{8}{Config.Port.http,}}
\L{\LB{}\Tab{8}{COMM\_NONBLOCKING,}}
\L{\LB{}\Tab{8}{\S{}\"HTTP Port\"\SE{});}}
\L{\LB{    leave\_suid();}}
\L{\LB{    \K{if} (theHttpConnection \< 0) \{}}
\L{\LB{}\Tab{8}{fatal(\S{}\"Cannot open HTTP Port\"\SE{});}}
\L{\LB{    \}}}
\L{\LB{    fd\_note(theHttpConnection, \S{}\"HTTP socket\"\SE{});}}
\L{\LB{    comm\_listen(theHttpConnection);}}
\L{\LB{    commSetSelect(theHttpConnection,}}
\L{\LB{}\Tab{8}{COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{8}{asciiHandleConn,}}
\L{\LB{}\Tab{8}{NULL, 0);}}
\L{\LB{    debug(1, 1, \S{}\"Accepting HTTP connections on FD \%d.\!n\"\SE{},}}
\L{\LB{}\Tab{8}{theHttpConnection);}}
\L{\LB{}}
\L{\LB{    \K{if} (!httpd\_accel\_mode \|\| Config.Accel.withProxy) \{}}
\L{\LB{}\Tab{8}{\K{if} ((port = Config.Port.icp) \> (u\_short) 0) \{}}
\L{\LB{}\Tab{8}{    enter\_suid();}}
\L{\LB{}\Tab{8}{    theInIcpConnection = comm\_open(SOCK\_DGRAM,}}
\L{\LB{}\Tab{16}{0,}}
\L{\LB{}\Tab{16}{Config.Addrs.udp\_incoming,}}
\L{\LB{}\Tab{16}{port,}}
\L{\LB{}\Tab{16}{COMM\_NONBLOCKING,}}
\L{\LB{}\Tab{16}{\S{}\"ICP Port\"\SE{});}}
\L{\LB{}\Tab{8}{    leave\_suid();}}
\L{\LB{}\Tab{8}{    \K{if} (theInIcpConnection \< 0)}}
\L{\LB{}\Tab{16}{fatal(\S{}\"Cannot open ICP Port\"\SE{});}}
\L{\LB{}\Tab{8}{    fd\_note(theInIcpConnection, \S{}\"ICP socket\"\SE{});}}
\L{\LB{}\Tab{8}{    commSetSelect(theInIcpConnection,}}
\L{\LB{}\Tab{16}{COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{16}{icpHandleUdp,}}
\L{\LB{}\Tab{16}{NULL, 0);}}
\L{\LB{}\Tab{8}{    comm\_join\_mcast\_groups(theInIcpConnection);}}
\L{\LB{}\Tab{8}{    debug(1, 1, \S{}\"Accepting ICP connections on FD \%d.\!n\"\SE{},}}
\L{\LB{}\Tab{16}{theInIcpConnection);}}
\L{\LB{}}
\L{\LB{}\Tab{8}{    \K{if} ((addr = Config.Addrs.udp\_outgoing).s\_addr != inaddr\_none) \{}}
\L{\LB{}\Tab{16}{enter\_suid();}}
\L{\LB{}\Tab{16}{theOutIcpConnection = comm\_open(SOCK\_DGRAM,}}
\L{\LB{}\Tab{16}{    0,}}
\L{\LB{}\Tab{16}{    addr,}}
\L{\LB{}\Tab{16}{    port,}}
\L{\LB{}\Tab{16}{    COMM\_NONBLOCKING,}}
\L{\LB{}\Tab{16}{    \S{}\"ICP Port\"\SE{});}}
\L{\LB{}\Tab{16}{leave\_suid();}}
\L{\LB{}\Tab{16}{\K{if} (theOutIcpConnection \< 0)}}
\L{\LB{}\Tab{16}{    fatal(\S{}\"Cannot open Outgoing ICP Port\"\SE{});}}
\L{\LB{}\Tab{16}{commSetSelect(theOutIcpConnection,}}
\L{\LB{}\Tab{16}{    COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{16}{    icpHandleUdp,}}
\L{\LB{}\Tab{16}{    NULL, 0);}}
\L{\LB{}\Tab{16}{debug(1, 1, \S{}\"Accepting ICP connections on FD \%d.\!n\"\SE{},}}
\L{\LB{}\Tab{16}{    theOutIcpConnection);}}
\L{\LB{}\Tab{16}{fd\_note(theOutIcpConnection, \S{}\"Outgoing ICP socket\"\SE{});}}
\L{\LB{}\Tab{16}{fd\_note(theInIcpConnection, \S{}\"Incoming ICP socket\"\SE{});}}
\L{\LB{}\Tab{8}{    \} \K{else} \{}}
\L{\LB{}\Tab{16}{theOutIcpConnection = theInIcpConnection;}}
\L{\LB{}\Tab{8}{    \}}}
\L{\LB{}\Tab{8}{    memset(\&theOutICPAddr, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} in\_addr));}}
\L{\LB{}\Tab{8}{    len = \K{sizeof}(\K{struct} sockaddr\_in);}}
\L{\LB{}\Tab{8}{    memset(\&xaddr, \S{}\'\!0\'\SE{}, len);}}
\L{\LB{}\Tab{8}{    x = getsockname(theOutIcpConnection,}}
\L{\LB{}\Tab{16}{(\K{struct} sockaddr *) \&xaddr, \&len);}}
\L{\LB{}\Tab{8}{    \K{if} (x \< 0)}}
\L{\LB{}\Tab{16}{debug(50, 1, \S{}\"theOutIcpConnection FD \%d: getsockname: \%s\!n\"\SE{},}}
\L{\LB{}\Tab{16}{    theOutIcpConnection, xstrerror());}}
\L{\LB{}\Tab{8}{    \K{else}}}
\L{\LB{}\Tab{16}{theOutICPAddr = xaddr.sin\_addr;}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{    \}}}
\L{\LB{    \K{if} (Config.vizHack.port) \{}}
\L{\LB{}\Tab{8}{vizSock = comm\_open(SOCK\_DGRAM,}}
\L{\LB{}\Tab{8}{    0,}}
\L{\LB{}\Tab{8}{    any\_addr,}}
\L{\LB{}\Tab{8}{    0,}}
\L{\LB{}\Tab{8}{    COMM\_NONBLOCKING,}}
\L{\LB{}\Tab{8}{    \S{}\"VizHack Port\"\SE{});}}
\L{\LB{}\Tab{8}{\K{if} (vizSock \< 0)}}
\L{\LB{}\Tab{8}{    fatal(\S{}\"Could not open Viz Socket\"\SE{});}}
\L{\LB{\K{\#if} defined(IP\_ADD\_MEMBERSHIP) \&\& defined(IP\_MULTICAST\_TTL)}}
\L{\LB{}\Tab{8}{\K{if} (Config.vizHack.addr.s\_addr \> inet\_addr(\S{}\"224.0.0.0\"\SE{})) \{}}
\L{\LB{}\Tab{8}{    \K{struct} ip\_mreq mr;}}
\L{\LB{}\Tab{8}{    \K{char} ttl = (\K{char}) Config.vizHack.mcast\_ttl;}}
\L{\LB{}\Tab{8}{    memset((\K{char} *) \&mr, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} ip\_mreq));}}
\L{\LB{}\Tab{8}{    mr.imr\_multiaddr.s\_addr = Config.vizHack.addr.s\_addr;}}
\L{\LB{}\Tab{8}{    mr.imr\_interface.s\_addr = INADDR\_ANY;}}
\L{\LB{}\Tab{8}{    x = setsockopt(vizSock,}}
\L{\LB{}\Tab{16}{IPPROTO\_IP,}}
\L{\LB{}\Tab{16}{IP\_ADD\_MEMBERSHIP,}}
\L{\LB{}\Tab{16}{(\K{char} *) \&mr,}}
\L{\LB{}\Tab{16}{\K{sizeof}(\K{struct} ip\_mreq));}}
\L{\LB{}\Tab{8}{    \K{if} (x \< 0)}}
\L{\LB{}\Tab{16}{debug(50, 1, \S{}\"IP\_ADD\_MEMBERSHIP: FD \%d, addr \%s: \%s\!n\"\SE{},}}
\L{\LB{}\Tab{16}{    vizSock, inet\_ntoa(Config.vizHack.addr), xstrerror());}}
\L{\LB{}\Tab{8}{    x = setsockopt(vizSock,}}
\L{\LB{}\Tab{16}{IPPROTO\_IP,}}
\L{\LB{}\Tab{16}{IP\_MULTICAST\_TTL,}}
\L{\LB{}\Tab{16}{\&ttl,}}
\L{\LB{}\Tab{16}{\K{sizeof}(\K{char}));}}
\L{\LB{}\Tab{8}{    \K{if} (x \< 0)}}
\L{\LB{}\Tab{16}{debug(50, 1, \S{}\"IP\_MULTICAST\_TTL: FD \%d, TTL \%d: \%s\!n\"\SE{},}}
\L{\LB{}\Tab{16}{    vizSock, Config.vizHack.mcast\_ttl, xstrerror());}}
\L{\LB{}\Tab{8}{    ttl = 0;}}
\L{\LB{}\Tab{8}{    x = \K{sizeof}(\K{char});}}
\L{\LB{}\Tab{8}{    getsockopt(vizSock, IPPROTO\_IP, IP\_MULTICAST\_TTL, \&ttl, \&x);}}
\L{\LB{}\Tab{8}{    debug(1, 0, \S{}\"vizSock on FD \%d, ttl=\%d\!n\"\SE{}, vizSock, (\K{int}) ttl);}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{\K{\#else}}}
\L{\LB{}\Tab{8}{debug(1, 0, \S{}\"vizSock: Could not join multicast group\!n\"\SE{});}}
\L{\LB{\K{\#endif}}}
\L{\LB{}\Tab{8}{memset((\K{char} *) \&Config.vizHack.S, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} sockaddr\_in));}}
\L{\LB{}\Tab{8}{Config.vizHack.S.sin\_family = AF\_INET;}}
\L{\LB{}\Tab{8}{Config.vizHack.S.sin\_addr = Config.vizHack.addr;}}
\L{\LB{}\Tab{8}{Config.vizHack.S.sin\_port = htons(Config.vizHack.port);}}
\L{\LB{    \}}}
\L{\LB{    clientdbInit();}}
\L{\LB{    icmpOpen();}}
\L{\LB{    netdbInit();}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{void}}}
\L{\LB{\Proc{serverConnectionsClose}serverConnectionsClose(\K{void})}}
\L{\LB{\{}}
\L{\LB{    \C{}\/* NOTE, this function will be called repeatedly while shutdown}}
\L{\LB{     * is pending *\/\CE{}}}
\L{\LB{    \K{if} (theHttpConnection \>= 0) \{}}
\L{\LB{}\Tab{8}{debug(1, 1, \S{}\"FD \%d Closing HTTP connection\!n\"\SE{},}}
\L{\LB{}\Tab{8}{    theHttpConnection);}}
\L{\LB{}\Tab{8}{comm\_close(theHttpConnection);}}
\L{\LB{}\Tab{8}{commSetSelect(theHttpConnection,}}
\L{\LB{}\Tab{8}{    COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{8}{    NULL,}}
\L{\LB{}\Tab{8}{    NULL, 0);}}
\L{\LB{}\Tab{8}{theHttpConnection = \-1;}}
\L{\LB{    \}}}
\L{\LB{    \K{if} (theInIcpConnection \>= 0) \{}}
\L{\LB{}\Tab{8}{\C{}\/* NOTE, don\'t close outgoing ICP connection, we need to write to}}
\L{\LB{}\Tab{8}{ * it during shutdown *\/\CE{}}}
\L{\LB{}\Tab{8}{debug(1, 1, \S{}\"FD \%d Closing ICP connection\!n\"\SE{},}}
\L{\LB{}\Tab{8}{    theInIcpConnection);}}
\L{\LB{}\Tab{8}{\K{if} (theInIcpConnection != theOutIcpConnection)}}
\L{\LB{}\Tab{8}{    comm\_close(theInIcpConnection);}}
\L{\LB{}\Tab{8}{commSetSelect(theInIcpConnection,}}
\L{\LB{}\Tab{8}{    COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{8}{    NULL,}}
\L{\LB{}\Tab{8}{    NULL, 0);}}
\L{\LB{}\Tab{8}{\K{if} (theInIcpConnection != theOutIcpConnection)}}
\L{\LB{}\Tab{8}{    commSetSelect(theOutIcpConnection,}}
\L{\LB{}\Tab{16}{COMM\_SELECT\_READ,}}
\L{\LB{}\Tab{16}{NULL,}}
\L{\LB{}\Tab{16}{NULL, 0);}}
\L{\LB{}\Tab{8}{theInIcpConnection = \-1;}}
\L{\LB{    \}}}
\L{\LB{    \K{if} (icmp\_sock \> \-1)}}
\L{\LB{}\Tab{8}{icmpClose();}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{mainReinitialize}mainReinitialize(\K{void})}}
\L{\LB{\{}}
\L{\LB{    debug(1, 0, \S{}\"Restarting Squid Cache (version \%s)...\!n\"\SE{}, version\_string);}}
\L{\LB{    \C{}\/* Already called serverConnectionsClose and ipcacheShutdownServers() *\/\CE{}}}
\L{\LB{    neighborsDestroy();}}
\L{\LB{    parseConfigFile(ConfigFile);}}
\L{\LB{    \_db\_init(Config.Log.log, Config.debugOptions);}}
\L{\LB{    dnsOpenServers();}}
\L{\LB{    redirectOpenServers();}}
\L{\LB{    serverConnectionsOpen();}}
\L{\LB{    (\K{void}) ftpInitialize();}}
\L{\LB{    \K{if} (theOutIcpConnection \>= 0 \&\& (!httpd\_accel\_mode \|\| Config.Accel.withProxy))}}
\L{\LB{}\Tab{8}{neighbors\_open(theOutIcpConnection);}}
\L{\LB{    debug(1, 0, \S{}\"Ready to serve requests.\!n\"\SE{});}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{mainInitialize}mainInitialize(\K{void})}}
\L{\LB{\{}}
\L{\LB{    \K{static} \K{int} first\_time = 1;}}
\L{\LB{    \K{if} (opt\_catch\_signals) \{}}
\L{\LB{}\Tab{8}{squid\_signal(SIGSEGV, death, SA\_NODEFER \| SA\_RESETHAND);}}
\L{\LB{}\Tab{8}{squid\_signal(SIGBUS, death, SA\_NODEFER \| SA\_RESETHAND);}}
\L{\LB{    \}}}
\L{\LB{    squid\_signal(SIGPIPE, SIG\_IGN, SA\_RESTART);}}
\L{\LB{    squid\_signal(SIGCHLD, sig\_child, SA\_NODEFER \| SA\_RESTART);}}
\L{\LB{}}
\L{\LB{    \K{if} (ConfigFile == NULL)}}
\L{\LB{}\Tab{8}{ConfigFile = xstrdup(DefaultConfigFile);}}
\L{\LB{    parseConfigFile(ConfigFile);}}
\L{\LB{}}
\L{\LB{    leave\_suid();}\Tab{32}{\C{}\/* Run as non privilegied user *\/\CE{}}}
\L{\LB{}}
\L{\LB{    \K{if} (httpPortNumOverride != 1)}}
\L{\LB{}\Tab{8}{Config.Port.http = (u\_short) httpPortNumOverride;}}
\L{\LB{    \K{if} (icpPortNumOverride != 1)}}
\L{\LB{}\Tab{8}{Config.Port.icp = (u\_short) icpPortNumOverride;}}
\L{\LB{}}
\L{\LB{    \_db\_init(Config.Log.log, Config.debugOptions);}}
\L{\LB{    fdstat\_open(fileno(debug\_log), FD\_LOG);}}
\L{\LB{    fd\_note(fileno(debug\_log), Config.Log.log);}}
\L{\LB{}}
\L{\LB{    debug(1, 0, \S{}\"Starting Squid Cache version \%s for \%s...\!n\"\SE{},}}
\L{\LB{}\Tab{8}{version\_string,}}
\L{\LB{}\Tab{8}{CONFIG\_HOST\_TYPE);}}
\L{\LB{    debug(1, 1, \S{}\"With \%d file descriptors available\!n\"\SE{}, SQUID\_MAXFD);}}
\L{\LB{}}
\L{\LB{    \K{if} (first\_time) \{}}
\L{\LB{}\Tab{8}{stmemInit();}\Tab{32}{\C{}\/* stmem must go before at least redirect *\/\CE{}}}
\L{\LB{}\Tab{8}{disk\_init();}\Tab{32}{\C{}\/* disk\_init must go before ipcache\_init() *\/\CE{}}}
\L{\LB{    \}}}
\L{\LB{    ipcache\_init();}}
\L{\LB{    fqdncache\_init();}}
\L{\LB{    dnsOpenServers();}}
\L{\LB{    redirectOpenServers();}}
\L{\LB{    useragentOpenLog();}}
\L{\LB{    (\K{void}) ftpInitialize();}}
\L{\LB{}}
\L{\LB{\K{\#if} MALLOC\_DBG}}
\L{\LB{    malloc\_debug(0, malloc\_debug\_level);}}
\L{\LB{\K{\#endif}}}
\L{\LB{}}
\L{\LB{    \K{if} (first\_time) \{}}
\L{\LB{}\Tab{8}{\C{}\/* module initialization *\/\CE{}}}
\L{\LB{}\Tab{8}{urlInitialize();}}
\L{\LB{}\Tab{8}{stat\_init(\&HTTPCacheInfo, Config.Log.access);}}
\L{\LB{}\Tab{8}{stat\_init(\&ICPCacheInfo, NULL);}}
\L{\LB{}\Tab{8}{storeInit();}}
\L{\LB{}}
\L{\LB{}\Tab{8}{\K{if} (Config.effectiveUser) \{}}
\L{\LB{}\Tab{8}{    \C{}\/* we were probably started as root, so cd to a swap}}
\L{\LB{}\Tab{8}{     * directory in case we dump core *\/\CE{}}}
\L{\LB{}\Tab{8}{    \K{if} (chdir(swappath(0)) \< 0) \{}}
\L{\LB{}\Tab{16}{debug(50, 0, \S{}\"\%s: \%s\!n\"\SE{}, swappath(0), xstrerror());}}
\L{\LB{}\Tab{16}{fatal\_dump(\S{}\"Cannot cd to swap directory?\"\SE{});}}
\L{\LB{}\Tab{8}{    \}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\C{}\/* after this point we want to see the mallinfo() output *\/\CE{}}}
\L{\LB{}\Tab{8}{do\_mallinfo = 1;}}
\L{\LB{    \}}}
\L{\LB{    serverConnectionsOpen();}}
\L{\LB{    \K{if} (theOutIcpConnection \>= 0 \&\& (!httpd\_accel\_mode \|\| Config.Accel.withProxy))}}
\L{\LB{}\Tab{8}{neighbors\_open(theOutIcpConnection);}}
\L{\LB{}}
\L{\LB{    \K{if} (first\_time)}}
\L{\LB{}\Tab{8}{writePidFile();}\Tab{32}{\C{}\/* write PID file *\/\CE{}}}
\L{\LB{}}
\L{\LB{    squid\_signal(SIGUSR1, rotate\_logs, SA\_RESTART);}}
\L{\LB{    squid\_signal(SIGUSR2, sigusr2\_handle, SA\_RESTART);}}
\L{\LB{    squid\_signal(SIGHUP, reconfigure, SA\_RESTART);}}
\L{\LB{    squid\_signal(SIGTERM, shut\_down, SA\_NODEFER \| SA\_RESETHAND \| SA\_RESTART);}}
\L{\LB{    squid\_signal(SIGINT, shut\_down, SA\_NODEFER \| SA\_RESETHAND \| SA\_RESTART);}}
\L{\LB{    debug(1, 0, \S{}\"Ready to serve requests.\!n\"\SE{});}}
\L{\LB{}}
\L{\LB{    \K{if} (first\_time) \{}}
\L{\LB{}\Tab{8}{eventAdd(\S{}\"storePurgeOld\"\SE{}, storePurgeOld, NULL, Config.cleanRate);}}
\L{\LB{}\Tab{8}{eventAdd(\S{}\"storeMaintain\"\SE{}, storeMaintainSwapSpace, NULL, 1);}}
\L{\LB{}\Tab{8}{eventAdd(\S{}\"storeDirClean\"\SE{}, storeDirClean, NULL, 15);}}
\L{\LB{}\Tab{8}{\K{if} (Config.Announce.on)}}
\L{\LB{}\Tab{8}{    eventAdd(\S{}\"send\_announce\"\SE{}, send\_announce, NULL, 3600);}}
\L{\LB{}\Tab{8}{eventAdd(\S{}\"ipcache\_purgelru\"\SE{}, (EVH) ipcache\_purgelru, NULL, 10);}}
\L{\LB{    \}}}
\L{\LB{    first\_time = 0;}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{int}}}
\L{\LB{\Proc{main}main(\K{int} argc, \K{char} **argv)}}
\L{\LB{\{}}
\L{\LB{    \K{int} errcount = 0;}}
\L{\LB{    \K{int} n;}\Tab{32}{\C{}\/* \# of GC\'d objects *\/\CE{}}}
\L{\LB{    time\_t loop\_delay;}}
\L{\LB{    \C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{    time\_t ltime, ctime;}}
\L{\LB{    \C{}\/* end DH changes *\/\CE{}}}
\L{\LB{}}
\L{\LB{    \C{}\/* call mallopt() before anything else *\/\CE{}}}
\L{\LB{\K{\#if} HAVE\_MALLOPT}}
\L{\LB{\K{\#ifdef} M\_GRAIN}}
\L{\LB{    \C{}\/* Round up all sizes to a multiple of this *\/\CE{}}}
\L{\LB{    mallopt(M\_GRAIN, 16);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\K{\#ifdef} M\_MXFAST}}
\L{\LB{    \C{}\/* biggest size that is considered a small block *\/\CE{}}}
\L{\LB{    mallopt(M\_MXFAST, 256);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\K{\#ifdef} M\_NBLKS}}
\L{\LB{    \C{}\/* allocate this many small blocks at once *\/\CE{}}}
\L{\LB{    mallopt(M\_NLBLKS, 32);}}
\L{\LB{\K{\#endif}}}
\L{\LB{\K{\#endif} \C{}\/* HAVE\_MALLOPT *\/\CE{}}}
\L{\LB{}}
\L{\LB{    memset(\&local\_addr, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} in\_addr));}}
\L{\LB{    local\_addr.s\_addr = inet\_addr(localhost);}}
\L{\LB{    memset(\&any\_addr, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} in\_addr));}}
\L{\LB{    any\_addr.s\_addr = inet\_addr(\S{}\"0.0.0.0\"\SE{});}}
\L{\LB{    memset(\&no\_addr, \S{}\'\!0\'\SE{}, \K{sizeof}(\K{struct} in\_addr));}}
\L{\LB{    no\_addr.s\_addr = inet\_addr(\S{}\"255.255.255.255\"\SE{});}}
\L{\LB{    inaddr\_none = inet\_addr(\S{}\"X\"\SE{});}}
\L{\LB{}}
\L{\LB{    errorInitialize();}}
\L{\LB{}}
\L{\LB{    squid\_starttime = getCurrentTime();}}
\L{\LB{    failure\_notify = fatal\_dump;}}
\L{\LB{}}
\L{\LB{    mainParseOptions(argc, argv);}}
\L{\LB{}}
\L{\LB{    \C{}\/* send signal to running copy and exit *\/\CE{}}}
\L{\LB{    \K{if} (opt\_send\_signal != \-1) \{}}
\L{\LB{}\Tab{8}{sendSignal();}}
\L{\LB{}\Tab{8}{\C{}\/* NOTREACHED *\/\CE{}}}
\L{\LB{    \}}}
\L{\LB{    setMaxFD();}}
\L{\LB{}}
\L{\LB{    \K{if} (opt\_catch\_signals)}}
\L{\LB{}\Tab{8}{\K{for} (n = SQUID\_MAXFD; n \> 2; n\-\-)}}
\L{\LB{}\Tab{8}{    close(n);}}
\L{\LB{}}
\L{\LB{    \C{}\/*init comm module *\/\CE{}}}
\L{\LB{    comm\_init();}}
\L{\LB{}}
\L{\LB{    \C{}\/* we have to init fdstat here. *\/\CE{}}}
\L{\LB{    fdstat\_init(PREOPEN\_FD);}}
\L{\LB{    fdstat\_open(0, FD\_LOG);}}
\L{\LB{    fdstat\_open(1, FD\_LOG);}}
\L{\LB{    fdstat\_open(2, FD\_LOG);}}
\L{\LB{    fd\_note(0, \S{}\"STDIN\"\SE{});}}
\L{\LB{    fd\_note(1, \S{}\"STDOUT\"\SE{});}}
\L{\LB{    fd\_note(2, \S{}\"STDERR\"\SE{});}}
\L{\LB{}}
\L{\LB{    \C{}\/* preinit for debug module *\/\CE{}}}
\L{\LB{    debug\_log = stderr;}}
\L{\LB{    hash\_init(0);}}
\L{\LB{}}
\L{\LB{    mainInitialize();}}
\L{\LB{}}
\L{\LB{    \C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{    \K{if} (opt\_dynamic\_hierarchy) \{}}
\L{\LB{      const \K{char} *myhostname = getMyHostname();}}
\L{\LB{      \K{if} ((addself()) != 0) \{}}
\L{\LB{}\Tab{8}{debug(1,0, \S{}\"Couldn\'t join network.\!n\"\SE{});}}
\L{\LB{      \}}}
\L{\LB{      ltime = squid\_starttime;}}
\L{\LB{      \C{}\/* get the listing *\/\CE{}}}
\L{\LB{      \K{if} ((getnet()) != 0) \{}}
\L{\LB{}\Tab{8}{debug(1, 0, \S{}\"Error in getting new network status.\!n\"\SE{});}}
\L{\LB{      \}}}
\L{\LB{      num\_hosts = dhBuildUI();}}
\L{\LB{    \}}}
\L{\LB{    \C{}\/* end DH changes *\/\CE{}}}
\L{\LB{}}
\L{\LB{    \C{}\/* main loop *\/\CE{}}}
\L{\LB{    \K{for} (;;) \{}}
\L{\LB{      \K{if} (rotate\_pending) \{}}
\L{\LB{}\Tab{8}{ftpServerClose();}}
\L{\LB{}\Tab{8}{icmpClose();}}
\L{\LB{}\Tab{8}{\_db\_rotate\_log();}\Tab{32}{\C{}\/* cache.log *\/\CE{}}}
\L{\LB{}\Tab{8}{storeWriteCleanLog();}}
\L{\LB{}\Tab{8}{storeRotateLog();}\Tab{32}{\C{}\/* store.log *\/\CE{}}}
\L{\LB{}\Tab{8}{stat\_rotate\_log();}\Tab{32}{\C{}\/* access.log *\/\CE{}}}
\L{\LB{}\Tab{8}{useragentRotateLog();}\Tab{32}{\C{}\/* useragent.log *\/\CE{}}}
\L{\LB{}\Tab{8}{(\K{void}) ftpInitialize();}}
\L{\LB{}\Tab{8}{icmpOpen();}}
\L{\LB{}\Tab{8}{rotate\_pending = 0;}}
\L{\LB{      \}}}
\L{\LB{      eventRun();}}
\L{\LB{      \K{if} ((loop\_delay = eventNextTime()) \< 0)}}
\L{\LB{}\Tab{8}{loop\_delay = 0;}}
\L{\LB{}}
\L{\LB{      \C{}\/* begin DH changes *\/\CE{}}}
\L{\LB{      ctime = getCurrentTime();}}
\L{\LB{      \K{if} ((ctime \- ltime)\>= UPDATE\_TIME) \{}}
\L{\LB{}\Tab{8}{getupdate(ltime);}}
\L{\LB{}\Tab{8}{ltime = ctime;}}
\L{\LB{}\Tab{8}{num\_hosts = dhBuildUI();}}
\L{\LB{      \}}}
\L{\LB{      \C{}\/* end DH changes*\/\CE{}}}
\L{\LB{}}
\L{\LB{      \K{switch} (comm\_select(loop\_delay)) \{}}
\L{\LB{      \K{case} COMM\_OK:}}
\L{\LB{}\Tab{8}{errcount = 0;}\Tab{24}{\C{}\/* reset if successful *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{break};}}
\L{\LB{      \K{case} COMM\_ERROR:}}
\L{\LB{}\Tab{8}{errcount++;}}
\L{\LB{}\Tab{8}{debug(1, 0, \S{}\"Select loop Error. Retry \%d\!n\"\SE{}, errcount);}}
\L{\LB{}\Tab{8}{\K{if} (errcount == 10)}}
\L{\LB{}\Tab{8}{  fatal\_dump(\S{}\"Select Loop failed!\"\SE{});}}
\L{\LB{}\Tab{8}{\K{break};}}
\L{\LB{      \K{case} COMM\_SHUTDOWN:}}
\L{\LB{}\Tab{8}{\C{}\/* delayed close so we can transmit while shutdown pending *\/\CE{}}}
\L{\LB{}\Tab{8}{\K{if} (theOutIcpConnection \> 0) \{}}
\L{\LB{}\Tab{8}{  comm\_close(theOutIcpConnection);}}
\L{\LB{}\Tab{8}{  theOutIcpConnection = \-1;}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{if} (shutdown\_pending) \{}}
\L{\LB{}\Tab{8}{  normal\_shutdown();}}
\L{\LB{}\Tab{8}{  exit(0);}}
\L{\LB{}\Tab{8}{\} \K{else} \K{if} (reread\_pending) \{}}
\L{\LB{}\Tab{8}{  mainReinitialize();}}
\L{\LB{}\Tab{8}{  reread\_pending = 0;}\Tab{32}{\C{}\/* reset *\/\CE{}}}
\L{\LB{}\Tab{8}{\} \K{else} \{}}
\L{\LB{}\Tab{8}{  fatal\_dump(\S{}\"MAIN: SHUTDOWN from comm\_select, but nothing pending.\"\SE{});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{break};}}
\L{\LB{      \K{case} COMM\_TIMEOUT:}}
\L{\LB{}\Tab{8}{\K{break};}}
\L{\LB{      \K{default}:}}
\L{\LB{}\Tab{8}{fatal\_dump(\S{}\"MAIN: Internal error \-\- this should never happen.\"\SE{});}}
\L{\LB{}\Tab{8}{\K{break};}}
\L{\LB{      \}}}
\L{\LB{    \}}}
\L{\LB{    \C{}\/* NOTREACHED *\/\CE{}}}
\L{\LB{    \K{return} 0;}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{static} \K{void}}}
\L{\LB{\Proc{sendSignal}sendSignal(\K{void})}}
\L{\LB{\{}}
\L{\LB{    pid\_t pid;}}
\L{\LB{    debug\_log = stderr;}}
\L{\LB{    \K{if} (ConfigFile == NULL)}}
\L{\LB{}\Tab{8}{ConfigFile = xstrdup(DefaultConfigFile);}}
\L{\LB{    parseConfigFile(ConfigFile);}}
\L{\LB{    pid = readPidFile();}}
\L{\LB{    \K{if} (pid \> 1) \{}}
\L{\LB{}\Tab{8}{\K{if} (kill(pid, opt\_send\_signal) \&\&}}
\L{\LB{}\Tab{8}{\C{}\/* ignore permissions if just running check *\/\CE{}}}
\L{\LB{}\Tab{8}{    !(opt\_send\_signal == 0 \&\& errno == EPERM)) \{}}
\L{\LB{}\Tab{8}{    fprintf(stderr, \S{}\"\%s: ERROR: Could not send \"\SE{}, appname);}}
\L{\LB{}\Tab{8}{    fprintf(stderr, \S{}\"signal \%d to process \%d: \%s\!n\"\SE{},}}
\L{\LB{}\Tab{16}{opt\_send\_signal, (\K{int}) pid, xstrerror());}}
\L{\LB{}\Tab{8}{    exit(1);}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{    \} \K{else} \{}}
\L{\LB{}\Tab{8}{fprintf(stderr, \S{}\"\%s: ERROR: No running copy\!n\"\SE{}, appname);}}
\L{\LB{}\Tab{8}{exit(1);}}
\L{\LB{    \}}}
\L{\LB{    \C{}\/* signal successfully sent *\/\CE{}}}
\L{\LB{    exit(0);}}
\L{\LB{\}}}
