-
Notifications
You must be signed in to change notification settings - Fork 493
/
main.cc
1796 lines (1348 loc) · 40.8 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* $Id: main.cc,v 1.459 2008/02/26 21:49:35 amosjeffries Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
* ----------------------------------------------------------
*
* Squid is the result of efforts by numerous individuals from
* the Internet community; see the CONTRIBUTORS file for full
* details. Many organizations have provided support for Squid's
* development; see the SPONSORS file for full details. Squid is
* Copyrighted (C) 2001 by the Regents of the University of
* California; see the COPYRIGHT file for full details. Squid
* incorporates software developed and/or copyrighted by other
* sources; see the CREDITS file for full details.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
*/
#include "squid.h"
#include "AccessLogEntry.h"
#include "authenticate.h"
#include "CacheManager.h"
#include "ConfigParser.h"
#include "errorpage.h"
#include "event.h"
#include "EventLoop.h"
#include "ExternalACL.h"
#include "Store.h"
#include "ICP.h"
#include "ident.h"
#include "HttpReply.h"
#include "pconn.h"
#include "Mem.h"
#include "ACLASN.h"
#include "ACL.h"
#include "htcp.h"
#include "StoreFileSystem.h"
#include "DiskIO/DiskIOModule.h"
#include "comm.h"
#if USE_EPOLL
#include "comm_epoll.h"
#endif
#if USE_KQUEUE
#include "comm_kqueue.h"
#endif
#if USE_POLL
#include "comm_poll.h"
#endif
#if defined(USE_SELECT) || defined(USE_SELECT_WIN32)
#include "comm_select.h"
#endif
#include "SquidTime.h"
#include "SwapDir.h"
#include "forward.h"
#include "MemPool.h"
#include "ICMPSquid.h"
#if USE_LOADABLE_MODULES
#include "LoadableModules.h"
#endif
#if ICAP_CLIENT
#include "ICAP/ICAPConfig.h"
#endif
#if USE_ADAPTATION
#include "adaptation/Config.h"
#endif
#if USE_WIN32_SERVICE
#include "squid_windows.h"
#include <process.h>
static int opt_install_service = FALSE;
static int opt_remove_service = FALSE;
static int opt_signal_service = FALSE;
static int opt_command_line = FALSE;
extern void WIN32_svcstatusupdate(DWORD, DWORD);
void WINAPI WIN32_svcHandler(DWORD);
#endif
/** for error reporting from xmalloc and friends */
SQUIDCEXTERN void (*failure_notify) (const char *);
static int opt_parse_cfg_only = 0;
static char *opt_syslog_facility = NULL;
static int icpPortNumOverride = 1; /* Want to detect "-u 0" */
static int configured_once = 0;
#if MALLOC_DBG
static int malloc_debug_level = 0;
#endif
static volatile int do_reconfigure = 0;
static volatile int do_rotate = 0;
static volatile int do_shutdown = 0;
static volatile int shutdown_status = 0;
static void mainRotate(void);
static void mainReconfigure(void);
static void mainInitialize(void);
static void usage(void);
static void mainParseOptions(int argc, char *argv[]);
static void sendSignal(void);
static void serverConnectionsOpen(void);
static void watch_child(char **);
static void setEffectiveUser(void);
#if MEM_GEN_TRACE
extern void log_trace_done();
extern void log_trace_init(char *);
#endif
static void SquidShutdown(void);
static void mainSetCwd(void);
static int checkRunningPid(void);
static CacheManager manager;
#ifndef _SQUID_MSWIN_
static const char *squid_start_script = "squid_start";
#endif
#if TEST_ACCESS
#include "test_access.c"
#endif
/** temporary thunk across to the unrefactored store interface */
class StoreRootEngine : public AsyncEngine
{
public:
int checkEvents(int timeout)
{
Store::Root().callback();
return EVENT_IDLE;
};
};
class SignalEngine: public AsyncEngine
{
public:
SignalEngine(EventLoop &loop) : loop(loop) {}
virtual int checkEvents(int timeout);
private:
static void StopEventLoop(void * data)
{
static_cast<SignalEngine *>(data)->loop.stop();
}
void doShutdown(time_t wait);
EventLoop &loop;
};
int
SignalEngine::checkEvents(int timeout)
{
PROF_start(SignalEngine_checkEvents);
if (do_reconfigure) {
mainReconfigure();
do_reconfigure = 0;
} else if (do_rotate) {
mainRotate();
do_rotate = 0;
} else if (do_shutdown) {
doShutdown(do_shutdown > 0 ? (int) Config.shutdownLifetime : 0);
do_shutdown = 0;
}
PROF_stop(SignalEngine_checkEvents);
return EVENT_IDLE;
}
void
SignalEngine::doShutdown(time_t wait)
{
debugs(1, 1, "Preparing for shutdown after " << statCounter.client_http.requests << " requests");
debugs(1, 1, "Waiting " << wait << " seconds for active connections to finish");
shutting_down = 1;
#if USE_WIN32_SERVICE
WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000);
#endif
serverConnectionsClose();
eventAdd("SquidShutdown", &StopEventLoop, this, (double) (wait + 1), 1, false);
}
static void
usage(void)
{
fprintf(stderr,
#if USE_WIN32_SERVICE
"Usage: %s [-cdhirvzCDFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal] [-n name] [-O CommandLine]\n"
#else
"Usage: %s [-cdhvzCDFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]\n"
#endif
" -a port Specify HTTP port number (default: %d).\n"
" -d level Write debugging to stderr also.\n"
" -f file Use given config-file instead of\n"
" %s\n"
" -h Print help message.\n"
#if USE_WIN32_SERVICE
" -i Installs as a Windows Service (see -n option).\n"
#endif
" -k reconfigure|rotate|shutdown|interrupt|kill|debug|check|parse\n"
" Parse configuration file, then send signal to \n"
" running copy (except -k parse) and exit.\n"
#if USE_WIN32_SERVICE
" -n name Specify Windows Service name to use for service operations\n"
" default is: " _WIN_SQUID_DEFAULT_SERVICE_NAME ".\n"
" -r Removes a Windows Service (see -n option).\n"
#endif
" -s | -l facility\n"
" Enable logging to syslog.\n"
" -u port Specify ICP port number (default: %d), disable with 0.\n"
" -v Print version.\n"
" -z Create swap directories\n"
" -C Do not catch fatal signals.\n"
" -D Disable initial DNS tests.\n"
" -F Don't serve any requests until store is rebuilt.\n"
" -N No daemon mode.\n"
#if USE_WIN32_SERVICE
" -O options\n"
" Set Windows Service Command line options in Registry.\n"
#endif
" -R Do not set REUSEADDR on port.\n"
" -S Double-check swap during rebuild.\n"
" -V Virtual host httpd-accelerator.\n"
" -X Force full debugging.\n"
" -Y Only return UDP_HIT or UDP_MISS_NOFETCH during fast reload.\n",
APP_SHORTNAME, CACHE_HTTP_PORT, DefaultConfigFile, CACHE_ICP_PORT);
exit(1);
}
/**
* Parse the parameters received via command line interface.
*
\param argc[in] Number of options received on command line
\param argv[in] List of parameters received on command line
*/
static void
mainParseOptions(int argc, char *argv[])
{
extern char *optarg;
int c;
#if USE_WIN32_SERVICE
while ((c = getopt(argc, argv, "CDFNO:RSVYXa:d:f:hik:m::n:rsl:u:vz?")) != -1)
#else
while ((c = getopt(argc, argv, "CDFNRSYXa:d:f:hk:m::sl:u:vz?")) != -1)
#endif
{
switch (c)
{
case 'C':
/** \par C
* Unset/disabel global option for catchign signals. opt_catch_signals */
opt_catch_signals = 0;
break;
case 'D':
/** \par D
* Unset/disable global option for optional DNS tests. opt_dns_tests */
opt_dns_tests = 0;
break;
case 'F':
/** \par F
* Set global option for foreground rebuild. opt_foreground_rebuild */
opt_foreground_rebuild = 1;
break;
case 'N':
/** \par N
* Set global option for 'no_daemon' mode. opt_no_daemon */
opt_no_daemon = 1;
break;
#if USE_WIN32_SERVICE
case 'O':
/** \par O
* Set global option. opt_command_lin and WIN32_Command_Line */
opt_command_line = 1;
WIN32_Command_Line = xstrdup(optarg);
break;
#endif
case 'R':
/** \par R
* Unset/disable global option opt_reuseaddr */
opt_reuseaddr = 0;
break;
case 'S':
/** \par S
* Set global option opt_store_doublecheck */
opt_store_doublecheck = 1;
break;
case 'X':
/** \par X
* Force full debugging */
Debug::parseOptions("debug_options ALL,9");
Config.onoff.debug_override_X = 1;
sigusr2_handle(SIGUSR2);
break;
case 'Y':
/** \par Y
* Set global option opt_reload_hit_only */
opt_reload_hit_only = 1;
break;
#if USE_WIN32_SERVICE
case 'i':
/** \par i
* Set global option opt_install_service (to TRUE) */
opt_install_service = TRUE;
break;
#endif
case 'a':
/** \par a
* Add optional HTTP port as given following the option */
add_http_port(optarg);
break;
case 'd':
/** \par d
* Set global option opt_debug_stderr to the number given follwoign the option */
opt_debug_stderr = atoi(optarg);
break;
case 'f':
/** \par f
* Load the file given instead of the default squid.conf. */
xfree(ConfigFile);
ConfigFile = xstrdup(optarg);
break;
case 'k':
/** \par k
* Run the administrative action given following the option */
/** \li When its an unknown option display the usage help. */
if ((int) strlen(optarg) < 1)
usage();
if (!strncmp(optarg, "reconfigure", strlen(optarg)))
/** \li On reconfigure send SIGHUP. */
opt_send_signal = SIGHUP;
else if (!strncmp(optarg, "rotate", strlen(optarg)))
/** \li On rotate send SIGQUIT or SIGUSR1. */
#ifdef _SQUID_LINUX_THREADS_
opt_send_signal = SIGQUIT;
#else
opt_send_signal = SIGUSR1;
#endif
else if (!strncmp(optarg, "debug", strlen(optarg)))
/** \li On debug send SIGTRAP or SIGUSR2. */
#ifdef _SQUID_LINUX_THREADS_
opt_send_signal = SIGTRAP;
#else
opt_send_signal = SIGUSR2;
#endif
else if (!strncmp(optarg, "shutdown", strlen(optarg)))
/** \li On shutdown send SIGTERM. */
opt_send_signal = SIGTERM;
else if (!strncmp(optarg, "interrupt", strlen(optarg)))
/** \li On interrupt send SIGINT. */
opt_send_signal = SIGINT;
else if (!strncmp(optarg, "kill", strlen(optarg)))
/** \li On kill send SIGKILL. */
opt_send_signal = SIGKILL;
#ifdef SIGTTIN
else if (!strncmp(optarg, "restart", strlen(optarg)))
/** \li On restart send SIGTTIN. (exit and restart by parent) */
opt_send_signal = SIGTTIN;
#endif
else if (!strncmp(optarg, "check", strlen(optarg)))
/** \li On check send 0 / SIGNULL. */
opt_send_signal = 0; /* SIGNULL */
else if (!strncmp(optarg, "parse", strlen(optarg)))
/** \li On parse set global flag to re-parse the config file only. */
opt_parse_cfg_only = 1;
else
usage();
break;
case 'm':
/** \par 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 */
if (optarg) {
#if MALLOC_DBG
malloc_debug_level = atoi(optarg);
#else
fatal("Need to add -DMALLOC_DBG when compiling to use -mX option");
#endif
} else {
#if XMALLOC_TRACE
xmalloc_trace = !xmalloc_trace;
#else
fatal("Need to configure --enable-xmalloc-debug-trace to use -m option");
#endif
}
break;
#if USE_WIN32_SERVICE
case 'n':
/** \par n
* Set global option opt_signal_service (to TRUE).
* Stores the additional parameter given in global WIN32_Service_name */
xfree(WIN32_Service_name);
WIN32_Service_name = xstrdup(optarg);
opt_signal_service = TRUE;
break;
case 'r':
/** \par r
* Set global option opt_remove_service (to TRUE) */
opt_remove_service = TRUE;
break;
#endif
case 'l':
/** \par l
* Stores the syslog facility name in global opt_syslog_facility
* then performs actions for -s option. */
opt_syslog_facility = xstrdup(optarg);
case 's':
/** \par s
* Initialize the syslog for output */
#if HAVE_SYSLOG
_db_set_syslog(opt_syslog_facility);
break;
#else
fatal("Logging to syslog not available on this platform");
/* NOTREACHED */
#endif
case 'u':
/** \par u
* Store the ICP port number given in global option icpPortNumOverride
* ensuring its a positive number. */
icpPortNumOverride = atoi(optarg);
if (icpPortNumOverride < 0)
icpPortNumOverride = 0;
break;
case 'v':
/** \par v
* Display squid version and build information. Then exit. */
printf("Squid Cache: Version %s\nconfigure options: %s\n", version_string, SQUID_CONFIGURE_OPTIONS);
#if USE_WIN32_SERVICE
printf("Compiled as Windows System Service.\n");
#endif
exit(0);
/* NOTREACHED */
case 'z':
/** \par z
* Set global option opt_debug_stderr and opt_create_swap_dirs */
opt_debug_stderr = 1;
opt_create_swap_dirs = 1;
break;
case 'h':
case '?':
default:
/** \par h,?, or unknown
* \copydoc usage() */
usage();
break;
}
}
}
/* ARGSUSED */
void
rotate_logs(int sig)
{
do_rotate = 1;
#ifndef _SQUID_MSWIN_
#if !HAVE_SIGACTION
signal(sig, rotate_logs);
#endif
#endif
}
/* ARGSUSED */
void
reconfigure(int sig)
{
do_reconfigure = 1;
#ifndef _SQUID_MSWIN_
#if !HAVE_SIGACTION
signal(sig, reconfigure);
#endif
#endif
}
void
shut_down(int sig)
{
do_shutdown = sig == SIGINT ? -1 : 1;
#ifdef SIGTTIN
if (SIGTTIN == sig)
shutdown_status = 1;
#endif
#ifndef _SQUID_MSWIN_
#ifdef KILL_PARENT_OPT
if (getppid() > 1) {
debugs(1, 1, "Killing RunCache, pid " << getppid());
if (kill(getppid(), sig) < 0)
debugs(1, 1, "kill " << getppid() << ": " << xstrerror());
}
#endif
#if SA_RESETHAND == 0
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
#endif
#endif
}
static void
serverConnectionsOpen(void)
{
clientOpenListenSockets();
icpConnectionsOpen();
#if USE_HTCP
htcpInit();
#endif
#ifdef SQUID_SNMP
snmpConnectionOpen();
#endif
#if USE_WCCP
wccpConnectionOpen();
#endif
#if USE_WCCPv2
wccp2ConnectionOpen();
#endif
clientdbInit();
icmpEngine.Open();
netdbInit();
asnInit();
ACL::Initialize();
peerSelectInit();
carpInit();
}
void
serverConnectionsClose(void)
{
assert(shutting_down || reconfiguring);
clientHttpConnectionsClose();
icpConnectionShutdown();
#if USE_HTCP
htcpSocketShutdown();
#endif
icmpEngine.Close();
#ifdef SQUID_SNMP
snmpConnectionShutdown();
#endif
#if USE_WCCP
wccpConnectionClose();
#endif
#if USE_WCCPv2
wccp2ConnectionClose();
#endif
asnFreeMemory();
}
static void
mainReconfigure(void)
{
debugs(1, 1, "Reconfiguring Squid Cache (version " << version_string << ")...");
reconfiguring = 1;
/* Already called serverConnectionsClose and ipcacheShutdownServers() */
serverConnectionsClose();
icpConnectionClose();
#if USE_HTCP
htcpSocketClose();
#endif
#ifdef SQUID_SNMP
snmpConnectionClose();
#endif
#if USE_DNSSERVERS
dnsShutdown();
#else
idnsShutdown();
#endif
redirectShutdown();
authenticateShutdown();
externalAclShutdown();
storeDirCloseSwapLogs();
storeLogClose();
accessLogClose();
useragentLogClose();
refererCloseLog();
errorClean();
enter_suid(); /* root to read config file */
parseConfigFile(ConfigFile, manager);
setUmask(Config.umask);
Mem::Report();
setEffectiveUser();
_db_init(Config.Log.log, Config.debugOptions);
ipcache_restart(); /* clear stuck entries */
authenticateUserCacheRestart(); /* clear stuck ACL entries */
fqdncache_restart(); /* sigh, fqdncache too */
parseEtcHosts();
errorInitialize(); /* reload error pages */
accessLogInit();
storeLogOpen();
useragentOpenLog();
refererOpenLog();
#if USE_DNSSERVERS
dnsInit();
#else
idnsInit();
#endif
redirectInit();
authenticateInit(&Config.authConfiguration);
externalAclInit();
#if USE_WCCP
wccpInit();
#endif
#if USE_WCCPv2
wccp2Init();
#endif
serverConnectionsOpen();
neighbors_init();
neighborsRegisterWithCacheManager(manager);
storeDirOpenSwapLogs();
mimeInit(Config.mimeTablePathname);
if (Config.onoff.announce) {
if (!eventFind(start_announce, NULL))
eventAdd("start_announce", start_announce, NULL, 3600.0, 1);
} else {
if (eventFind(start_announce, NULL))
eventDelete(start_announce, NULL);
}
writePidFile(); /* write PID file */
debugs(1, 1, "Ready to serve requests.");
reconfiguring = 0;
}
static void
mainRotate(void)
{
icmpEngine.Close();
#if USE_DNSSERVERS
dnsShutdown();
#endif
redirectShutdown();
authenticateShutdown();
externalAclShutdown();
_db_rotate_log(); /* cache.log */
storeDirWriteCleanLogs(1);
storeLogRotate(); /* store.log */
accessLogRotate(); /* access.log */
useragentRotateLog(); /* useragent.log */
refererRotateLog(); /* referer.log */
#if WIP_FWD_LOG
fwdLogRotate();
#endif
icmpEngine.Open();
#if USE_DNSSERVERS
dnsInit();
#endif
redirectInit();
authenticateInit(&Config.authConfiguration);
externalAclInit();
}
static void
setEffectiveUser(void)
{
keepCapabilities();
leave_suid(); /* Run as non privilegied user */
#ifdef _SQUID_OS2_
return;
#endif
if (geteuid() == 0) {
debugs(0, 0, "Squid is not safe to run as root! If you must");
debugs(0, 0, "start Squid as root, then you must configure");
debugs(0, 0, "it to run as a non-priveledged user with the");
debugs(0, 0, "'cache_effective_user' option in the config file.");
fatal("Don't run Squid as root, set 'cache_effective_user'!");
}
}
static void
mainSetCwd(void)
{
char pathbuf[MAXPATHLEN];
if (Config.coredump_dir) {
if (0 == strcmp("none", Config.coredump_dir)) {
(void) 0;
} else if (chdir(Config.coredump_dir) == 0) {
debugs(0, 1, "Set Current Directory to " << Config.coredump_dir);
return;
} else {
debugs(50, 0, "chdir: " << Config.coredump_dir << ": " << xstrerror());
}
}
/* If we don't have coredump_dir or couldn't cd there, report current dir */
if (getcwd(pathbuf, MAXPATHLEN)) {
debugs(0, 1, "Current Directory is " << pathbuf);
} else {
debugs(50, 0, "WARNING: Can't find current directory, getcwd: " << xstrerror());
}
}
#if DELAY_POOLS
#include "DelayPools.h"
#endif
static void
mainInitialize(void)
{
/* chroot if configured to run inside chroot */
if (Config.chroot_dir && (chroot(Config.chroot_dir) != 0 || chdir("/") != 0)) {
fatal("failed to chroot");
}
if (opt_catch_signals) {
squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND);
squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND);
}
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
setEffectiveUser();
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
_db_init(Config.Log.log, Config.debugOptions);
fd_open(fileno(debug_log), FD_LOG, Config.Log.log);
#if MEM_GEN_TRACE
log_trace_init("/tmp/squid.alloc");
#endif
debugs(1, 0, "Starting Squid Cache version " << version_string << " for " << CONFIG_HOST_TYPE << "...");
#ifdef _SQUID_WIN32_
if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
debugs(1, 0, "Running as " << WIN32_Service_name << " Windows System Service on " << WIN32_OS_string);
debugs(1, 0, "Service command line is: " << WIN32_Service_Command_Line);
} else
debugs(1, 0, "Running on " << WIN32_OS_string);
#endif
debugs(1, 1, "Process ID " << getpid());
debugs(1, 1, "With " << Squid_MaxFD << " file descriptors available");
#ifdef _SQUID_MSWIN_
debugs(1, 1, "With " << _getmaxstdio() << " CRT stdio descriptors available");
if (WIN32_Socks_initialized)
debugs(1, 1, "Windows sockets initialized");
if (WIN32_OS_version > _WIN_OS_WINNT) {
WIN32_IpAddrChangeMonitorInit();
}
#endif
if (!configured_once)
disk_init(); /* disk_init must go before ipcache_init() */
ipcache_init();
fqdncache_init();
parseEtcHosts();
#if USE_DNSSERVERS
dnsInit();
#else
idnsInit();
#endif
redirectInit();
authenticateInit(&Config.authConfiguration);
externalAclInit();
useragentOpenLog();
refererOpenLog();
httpHeaderInitModule(); /* must go before any header processing (e.g. the one in errorInitialize) */
httpReplyInitModule(); /* must go before accepting replies */
errorInitialize();
accessLogInit();
#if USE_IDENT
identInit();
#endif
#ifdef SQUID_SNMP
snmpInit();
#endif
#if MALLOC_DBG
malloc_debug(0, malloc_debug_level);
#endif
if (!configured_once) {
#if USE_UNLINKD
unlinkdInit();
#endif
urlInitialize();
statInit();
storeInit();
mainSetCwd();
/* after this point we want to see the mallinfo() output */
do_mallinfo = 1;
mimeInit(Config.mimeTablePathname);
refreshInit();
#if DELAY_POOLS
DelayPools::Init();
#endif
FwdState::initModule();
/* register the modules in the cache manager menus */
accessLogRegisterWithCacheManager(manager);
asnRegisterWithCacheManager(manager);
authenticateRegisterWithCacheManager(&Config.authConfiguration, manager);
#if USE_CARP
carpRegisterWithCacheManager(manager);
#endif
cbdataRegisterWithCacheManager(manager);
/* These use separate calls so that the comm loops can eventually
* coexist.
*/
#ifdef USE_EPOLL
commEPollRegisterWithCacheManager(manager);
#endif
#ifdef USE_KQUEUE
commKQueueRegisterWithCacheManager(manager);
#endif
#ifdef USE_POLL
commPollRegisterWithCacheManager(manager);
#endif
#if defined(USE_SELECT) || defined(USE_SELECT_WIN32)
commSelectRegisterWithCacheManager(manager);
#endif
clientdbRegisterWithCacheManager(manager);
#if DELAY_POOLS
DelayPools::RegisterWithCacheManager(manager);