main.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 01 Startup and Main Loop */
10
11#include "squid.h"
12#include "AccessLogEntry.h"
13//#include "acl/Acl.h"
14#include "acl/Asn.h"
15#include "acl/forward.h"
16#include "anyp/UriScheme.h"
17#include "auth/Config.h"
18#include "auth/Gadgets.h"
19#include "AuthReg.h"
21#include "base/Subscription.h"
22#include "base/TextException.h"
23#include "cache_cf.h"
24#include "CachePeer.h"
25#include "carp.h"
26#include "client_db.h"
27#include "client_side.h"
28#include "comm.h"
29#include "CommandLine.h"
30#include "ConfigParser.h"
31#include "CpuAffinity.h"
32#include "debug/Messages.h"
33#include "DiskIO/DiskIOModule.h"
34#include "dns/forward.h"
35#include "errorpage.h"
36#include "event.h"
37#include "EventLoop.h"
38#include "ExternalACL.h"
39#include "fd.h"
40#include "format/Token.h"
41#include "fqdncache.h"
42#include "fs/Module.h"
43#include "fs_io.h"
44#include "FwdState.h"
45#include "globals.h"
46#include "htcp.h"
47#include "http/Stream.h"
48#include "HttpHeader.h"
49#include "HttpReply.h"
50#include "icmp/IcmpSquid.h"
51#include "icmp/net_db.h"
52#include "ICP.h"
53#include "Instance.h"
54#include "ip/tools.h"
55#include "ipc/Coordinator.h"
56#include "ipc/Kids.h"
57#include "ipc/Strand.h"
58#include "ipcache.h"
59#include "mime.h"
60#include "neighbors.h"
61#include "parser/Tokenizer.h"
62#include "Parsing.h"
63#include "pconn.h"
64#include "peer_sourcehash.h"
65#include "peer_userhash.h"
66#include "PeerSelectState.h"
67#include "protos.h"
68#include "redirect.h"
69#include "refresh.h"
70#include "sbuf/Stream.h"
71#include "SBufStatsAction.h"
72#include "SquidConfig.h"
73#include "stat.h"
74#include "StatCounters.h"
75#include "Store.h"
76#include "store/Disks.h"
77#include "store_log.h"
78#include "StoreFileSystem.h"
79#include "time/Engine.h"
80#include "tools.h"
81#include "unlinkd.h"
82#include "wccp.h"
83#include "wccp2.h"
84#include "WinSvc.h"
85
86#if USE_ADAPTATION
87#include "adaptation/Config.h"
88#endif
89#if USE_ECAP
91#endif
92#if ICAP_CLIENT
95#endif
96#if USE_DELAY_POOLS
97#include "ClientDelayConfig.h"
98#endif
99#if USE_DELAY_POOLS
100#include "DelayPools.h"
101#endif
102#if USE_LOADABLE_MODULES
103#include "LoadableModules.h"
104#endif
105#if USE_OPENSSL
106#include "ssl/context_storage.h"
107#include "ssl/helper.h"
108#endif
109#if ICAP_CLIENT
111#endif
112#if USE_ECAP
114#endif
115#if USE_ADAPTATION
116#include "adaptation/Config.h"
117#endif
118#if SQUID_SNMP
119#include "snmp_core.h"
120#endif
121
122#include <cerrno>
123#if HAVE_GETOPT_H
124#include <getopt.h>
125#endif
126#if HAVE_PATHS_H
127#include <paths.h>
128#endif
129#if HAVE_SYS_WAIT_H
130#include <sys/wait.h>
131#endif
132
133#if USE_WIN32_SERVICE
134#include <process.h>
135
139void WIN32_svcstatusupdate(DWORD, DWORD);
140void WINAPI WIN32_svcHandler(DWORD);
141#endif
142
144static char *opt_syslog_facility = nullptr;
145static int icpPortNumOverride = 1; /* Want to detect "-u 0" */
146static int configured_once = 0;
147#if MALLOC_DBG
148static int malloc_debug_level = 0;
149#endif
150static volatile int do_reconfigure = 0;
151static volatile int do_rotate = 0;
152static volatile int do_shutdown = 0;
153static volatile int do_revive_kids = 0;
154static volatile int shutdown_status = EXIT_SUCCESS;
155static volatile int do_handle_stopped_child = 0;
156
157static int RotateSignal = -1;
158static int ReconfigureSignal = -1;
159static int ShutdownSignal = -1;
160static int ReviveKidsSignal = -1;
161
162static void mainRotate(void);
163static void mainReconfigureStart(void);
164static void mainReconfigureFinish(void*);
165static void mainInitialize(void);
166static void usage(void);
167static void mainHandleCommandLineOption(const int optId, const char *optValue);
168static void sendSignal(void);
169static void serverConnectionsOpen(void);
170static void serverConnectionsClose(void);
171static void watch_child(const CommandLine &);
172static void setEffectiveUser(void);
173static void SquidShutdown(void);
174static void mainSetCwd(void);
175
176#if !_SQUID_WINDOWS_
177static const char *squid_start_script = "squid_start";
178#endif
179
180#if TEST_ACCESS
181#include "test_access.c"
182#endif
183
187{
188
189public:
190 int checkEvents(int) override {
192 return EVENT_IDLE;
193 };
194};
195
197{
198
199public:
200 int checkEvents(int timeout) override;
201
202private:
203 static void StopEventLoop(void *) {
206 }
207
208 static void FinalShutdownRunners(void *) {
210
211 // XXX: this should be a Runner.
212#if USE_AUTH
213 /* detach the auth components (only do this on full shutdown) */
215#endif
216
217 eventAdd("SquidTerminate", &StopEventLoop, nullptr, 0, 1, false);
218 }
219
220 void doShutdown(time_t wait);
221 void handleStoppedChild();
222};
223
224int
226{
227 if (do_reconfigure)
229 else if (do_rotate)
230 mainRotate();
231 else if (do_shutdown)
235 return EVENT_IDLE;
236}
237
240static bool
241AvoidSignalAction(const char *description, volatile int &signalVar)
242{
243 const char *avoiding = "delaying";
244 const char *currentEvent = "none";
245 if (shutting_down) {
246 currentEvent = "shutdown";
247 avoiding = "canceling";
248 // do not avoid repeated shutdown signals
249 // which just means the user wants to skip/abort shutdown timeouts
250 if (strcmp(currentEvent, description) == 0)
251 return false;
252 signalVar = 0;
253 }
254 else if (!configured_once)
255 currentEvent = "startup";
256 else if (reconfiguring)
257 currentEvent = "reconfiguration";
258 else {
259 signalVar = 0;
260 return false; // do not avoid (i.e., execute immediately)
261 // the caller may produce a signal-specific debugging message
262 }
263
264 debugs(1, DBG_IMPORTANT, avoiding << ' ' << description <<
265 " request during " << currentEvent);
266 return true;
267}
268
269void
271{
272 if (AvoidSignalAction("shutdown", do_shutdown))
273 return;
274
275 debugs(1, Important(2), "Preparing for shutdown after " << statCounter.client_http.requests << " requests");
276 debugs(1, Important(3), "Waiting " << wait << " seconds for active connections to finish");
277
278 if (shutting_down) {
279 // Already a shutdown signal has received and shutdown is in progress.
280 // Shutdown as soon as possible.
281 wait = 0;
282 } else {
283 shutting_down = 1;
284
285 /* run the closure code which can be shared with reconfigure */
287
289 }
290
291#if USE_WIN32_SERVICE
292 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000);
293#endif
294
295 eventAdd("SquidShutdown", &FinalShutdownRunners, this, (double) (wait + 1), 1, false);
296}
297
298void
300{
301 // no AvoidSignalAction() call: This code can run at any time because it
302 // does not depend on Squid state. It does not need debugging because it
303 // handles an "internal" signal, not an external/admin command.
305#if !_SQUID_WINDOWS_
306 PidStatus status;
307 pid_t pid;
308
309 do {
310 pid = WaitForAnyPid(status, WNOHANG);
311
312#if HAVE_SIGACTION
313
314 } while (pid > 0);
315
316#else
317
318 }
319 while (pid > 0 || (pid < 0 && errno == EINTR));
320#endif
321#endif
322}
323
324static void
325usage(void)
326{
327 fprintf(stderr,
328 "Usage: %s [-cdzCFNRVYX] [-n name] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]"
329#if USE_WIN32_SERVICE
330 "[-ir] [-O CommandLine]"
331#endif
332 "\n"
333 " -h | --help Print help message.\n"
334 " -v | --version Print version details.\n"
335 "\n"
336 " -a port Specify HTTP port number (default: %d).\n"
337 " -d level Write debugging to stderr also.\n"
338 " -f file Use given config-file instead of\n"
339 " %s\n"
340#if USE_WIN32_SERVICE
341 " -i Installs as a Windows Service (see -n option).\n"
342#endif
343 " -k reconfigure|rotate|shutdown|"
344#ifdef SIGTTIN
345 "restart|"
346#endif
347 "interrupt|kill|debug|check|parse\n"
348 " Parse configuration file, then send signal to \n"
349 " running copy (except -k parse) and exit.\n"
350 " -n name Specify service name to use for service operations\n"
351 " default is: " APP_SHORTNAME ".\n"
352#if USE_WIN32_SERVICE
353 " -r Removes a Windows Service (see -n option).\n"
354#endif
355 " -s | -l facility\n"
356 " Enable logging to syslog.\n"
357 " -u port Specify ICP port number (default: %d), disable with 0.\n"
358 " -z Create missing swap directories and then exit.\n"
359 " -C Do not catch fatal signals.\n"
360 " -D OBSOLETE. Scheduled for removal.\n"
361 " -F Don't serve any requests until store is rebuilt.\n"
362 " -N Master process runs in foreground and is a worker. No kids.\n"
363 " --foreground\n"
364 " Master process runs in foreground and creates worker kids.\n"
365 " --kid role-ID\n"
366 " Play a given SMP kid process role, with a given ID. Do not use\n"
367 " this option. It is meant for the master process use only.\n"
368#if USE_WIN32_SERVICE
369 " -O options\n"
370 " Set Windows Service Command line options in Registry.\n"
371#endif
372 " -R Do not set REUSEADDR on port.\n"
373 " -S Double-check swap during rebuild.\n"
374 " -X Force full debugging.\n"
375 " Add -d9 to also write full debugging to stderr.\n"
376 " -Y Only return UDP_HIT or UDP_MISS_NOFETCH during fast reload.\n",
377 APP_SHORTNAME, CACHE_HTTP_PORT, DEFAULT_CONFIG_FILE, CACHE_ICP_PORT);
378 exit(EXIT_FAILURE);
379}
380
382enum {
383 // The absolute values do not matter except that the following values should
384 // not be used: Values below 2 are for special getopt_long(3) use cases, and
385 // values in the [33,126] range are reserved for short options (-x).
387 optKid
389
390// short options
391// TODO: consider prefixing with ':' for better logging
392// (distinguish missing required argument cases)
393static const char *shortOpStr =
394#if USE_WIN32_SERVICE
395 "O:Vir"
396#endif
397 "CDFNRSYXa:d:f:hk:m::n:sl:u:vz?";
398
399// long options
400static struct option squidOptions[] = {
401 {"foreground", no_argument, nullptr, optForeground},
402 {"kid", required_argument, nullptr, optKid},
403 {"help", no_argument, nullptr, 'h'},
404 {"version", no_argument, nullptr, 'v'},
405 {nullptr, 0, nullptr, 0}
406};
407
408// handle a command line parameter
409static void
410mainHandleCommandLineOption(const int optId, const char *optValue)
411{
412 switch (optId) {
413
414 case 'C':
418 break;
419
420 case 'D':
423 debugs(1,DBG_CRITICAL, "WARNING: -D command-line option is obsolete.");
424 break;
425
426 case 'F':
430 break;
431
432 case 'N':
435 opt_no_daemon = 1;
436 break;
437
438#if USE_WIN32_SERVICE
439
440 case 'O':
444 WIN32_Command_Line = xstrdup(optValue);
445 break;
446#endif
447
448 case 'R':
451 opt_reuseaddr = 0;
452 break;
453
454 case 'S':
458 break;
459
460 case 'X':
463 Debug::parseOptions("rotate=0 ALL,9");
465 sigusr2_handle(SIGUSR2);
466 break;
467
468 case 'Y':
472 break;
473
474#if USE_WIN32_SERVICE
475
476 case 'i':
480 break;
481#endif
482
483 case 'a':
484 {
487 char *port = xstrdup(optValue);
488 // use a copy to avoid optValue modification
490 xfree(port);
491 break;
492 }
493
494 case 'd':
499 break;
500
501 case 'f':
505 ConfigFile = xstrdup(optValue);
506 break;
507
508 case 'k':
513 if (!optValue || strlen(optValue) < 1)
514 usage();
515
516 else if (!strncmp(optValue, "reconfigure", strlen(optValue)))
518 opt_send_signal = SIGHUP;
519 else if (!strncmp(optValue, "rotate", strlen(optValue)))
521#if defined(_SQUID_LINUX_THREADS_)
522 opt_send_signal = SIGQUIT;
523#else
524 opt_send_signal = SIGUSR1;
525#endif
526
527 else if (!strncmp(optValue, "debug", strlen(optValue)))
529#if defined(_SQUID_LINUX_THREADS_)
530 opt_send_signal = SIGTRAP;
531#else
532 opt_send_signal = SIGUSR2;
533#endif
534
535 else if (!strncmp(optValue, "shutdown", strlen(optValue)))
537 opt_send_signal = SIGTERM;
538 else if (!strncmp(optValue, "interrupt", strlen(optValue)))
540 opt_send_signal = SIGINT;
541 else if (!strncmp(optValue, "kill", strlen(optValue)))
542 // XXX: In SMP mode, uncatchable SIGKILL only kills the master process
544 opt_send_signal = SIGKILL;
545
546#ifdef SIGTTIN
547
548 else if (!strncmp(optValue, "restart", strlen(optValue)))
550 opt_send_signal = SIGTTIN;
551
552#endif
553
554 else if (!strncmp(optValue, "check", strlen(optValue)))
556 opt_send_signal = 0; /* SIGNULL */
557 else if (!strncmp(optValue, "parse", strlen(optValue)))
560 else
561 usage();
562
563 // Cannot use cache.log: use stderr for important messages (by default)
564 // and stop expecting a Debug::UseCacheLog() call.
567 break;
568
569 case 'm':
573 if (optValue) {
574#if MALLOC_DBG
575 malloc_debug_level = xatoi(optValue);
576#else
577 fatal("Need to add -DMALLOC_DBG when compiling to use -mX option");
578#endif
579
580 }
581 break;
582
583 case 'n':
587 if (optValue && *optValue != '\0') {
588 const SBuf t(optValue);
591 if (!tok.prefix(service_name, chr))
592 fatalf("Expected alphanumeric service name for the -n option but got: %s", optValue);
593 if (!tok.atEnd())
594 fatalf("Garbage after alphanumeric service name in the -n option value: %s", optValue);
595 if (service_name.length() > 32)
596 fatalf("Service name (-n option) must be limited to 32 characters but got %u", service_name.length());
597 opt_signal_service = true;
598 } else {
599 fatal("A service name is required for the -n option");
600 }
601 break;
602
603#if USE_WIN32_SERVICE
604
605 case 'r':
609
610 break;
611
612#endif
613
614 case 'l':
618 xfree(opt_syslog_facility); // ignore any previous options sent
619 opt_syslog_facility = xstrdup(optValue);
621 break;
622
623 case 's':
627 break;
628
629 case 'u':
633 icpPortNumOverride = atoi(optValue);
634
635 if (icpPortNumOverride < 0)
637
638 break;
639
640 case 'v':
643 printf("Squid Cache: Version %s\n",version_string);
644 printf("Service Name: " SQUIDSBUFPH "\n", SQUIDSBUFPRINT(service_name));
645 if (strlen(SQUID_BUILD_INFO))
646 printf("%s\n",SQUID_BUILD_INFO);
647#if USE_OPENSSL
648 printf("\nThis binary uses %s. ", OpenSSL_version(OPENSSL_VERSION));
649#if OPENSSL_VERSION_MAJOR < 3
650 printf("For legal restrictions on distribution see https://www.openssl.org/source/license.html\n\n");
651#endif
652#endif
653 printf( "configure options: %s\n", SQUID_CONFIGURE_OPTIONS);
654
655#if USE_WIN32_SERVICE
656
657 printf("Compiled as Windows System Service.\n");
658
659#endif
660
661 exit(EXIT_SUCCESS);
662
663 /* NOTREACHED */
664
665 case 'z':
669 // We will use cache.log, but this command is often executed on the
670 // command line, so use stderr to show important messages (by default).
671 // TODO: Generalize/fix this -z-specific and sometimes faulty logic with
672 // "use stderr when it is a tty [until we GoIntoBackground()]" logic.
674 break;
675
676 case optForeground:
679 opt_foreground = 1;
680 break;
681
682 case optKid:
683 // already processed in ConfigureCurrentKid()
684 break;
685
686 case 'h':
687
688 case '?':
689
690 default:
693 usage();
694
695 break;
696 }
697}
698
699/* ARGSUSED */
700void
702{
703 do_rotate = 1;
704 RotateSignal = sig;
705#if !_SQUID_WINDOWS_
706#if !HAVE_SIGACTION
707
708 signal(sig, rotate_logs);
709#endif
710#endif
711}
712
713/* ARGSUSED */
714void
716{
717 do_reconfigure = 1;
718 ReconfigureSignal = sig;
719#if !_SQUID_WINDOWS_
720#if !HAVE_SIGACTION
721
722 signal(sig, reconfigure);
723#endif
724#endif
725}
726
727static void
729{
730 ReviveKidsSignal = sig;
731 do_revive_kids = true;
732
733#if !_SQUID_WINDOWS_
734#if !HAVE_SIGACTION
735 signal(sig, master_revive_kids);
736#endif
737#endif
738}
739
741static void
743{
744 do_shutdown = 1;
745 ShutdownSignal = sig;
746
747#if !_SQUID_WINDOWS_
748#if !HAVE_SIGACTION
749 signal(sig, master_shutdown);
750#endif
751#endif
752
753}
754
755void
756shut_down(int sig)
757{
758 do_shutdown = sig == SIGINT ? -1 : 1;
759 ShutdownSignal = sig;
760#if defined(SIGTTIN)
761 if (SIGTTIN == sig)
762 shutdown_status = EXIT_FAILURE;
763#endif
764
765#if !defined(_SQUID_WINDOWS_) && !defined(HAVE_SIGACTION)
766 signal(sig, shut_down);
767#endif
768}
769
770void
771sig_child(int sig)
772{
774
775#if !defined(_SQUID_WINDOWS_) && !defined(HAVE_SIGACTION)
776 signal(sig, sig_child);
777#else
778 (void)sig;
779#endif
780}
781
782static void
784{
785 if (IamPrimaryProcess()) {
786#if USE_WCCP
788#endif
789
790#if USE_WCCPv2
791
793#endif
794 }
795 // start various proxying services if we are responsible for them
796 if (IamWorkerProcess()) {
798 icpOpenPorts();
799#if USE_HTCP
801#endif
802#if SQUID_SNMP
804#endif
805
807 netdbInit();
808 asnInit();
811
812 carpInit();
813#if USE_AUTH
815#endif
817 }
818}
819
820static void
822{
824
825 if (IamPrimaryProcess()) {
826#if USE_WCCP
827
829#endif
830#if USE_WCCPv2
831
833#endif
834 }
835 if (IamWorkerProcess()) {
838#if USE_HTCP
840#endif
841
843#if SQUID_SNMP
845#endif
846
848 }
849}
850
851static void
853{
854 if (AvoidSignalAction("reconfiguration", do_reconfigure))
855 return;
856
857 debugs(1, DBG_IMPORTANT, "Reconfiguring Squid Cache (version " << version_string << ")...");
858 reconfiguring = 1;
859
861
862 // Initiate asynchronous closing sequence
865#if USE_HTCP
867#endif
868#if USE_OPENSSL
870#endif
871#if USE_AUTH
873#endif
878#if ICAP_CLIENT
879 icapLogClose();
880#endif
882
883 eventAdd("mainReconfigureFinish", &mainReconfigureFinish, nullptr, 0, 1,
884 false);
885}
886
887static void
889{
890 debugs(1, 3, "finishing reconfiguring");
891
892 errorClean();
893 enter_suid(); /* root to read config file */
894
895 // we may have disabled the need for PURGE
898
899 // parse the config returns a count of errors encountered.
900 const int oldWorkers = Config.workers;
901 try {
902 if (parseConfigFile(ConfigFile) != 0) {
903 // for now any errors are a fatal condition...
905 }
906 } catch (...) {
907 // for now any errors are a fatal condition...
908 debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file. " <<
909 " Run squid -k parse and check for errors.");
911 }
912
913 if (oldWorkers != Config.workers) {
914 debugs(1, DBG_CRITICAL, "WARNING: Changing 'workers' (from " <<
915 oldWorkers << " to " << Config.workers <<
916 ") requires a full restart. It has been ignored by reconfigure.");
917 Config.workers = oldWorkers;
918 }
919
921
922 if (IamPrimaryProcess())
925
929 ipcache_restart(); /* clear stuck entries */
930 fqdncache_restart(); /* sigh, fqdncache too */
932 errorInitialize(); /* reload error pages */
934
935#if USE_LOADABLE_MODULES
937#endif
938
939#if USE_ADAPTATION
940 bool enableAdaptation = false;
941#if ICAP_CLIENT
943 enableAdaptation = Adaptation::Icap::TheConfig.onoff || enableAdaptation;
944#endif
945#if USE_ECAP
946 Adaptation::Ecap::TheConfig.finalize(); // must be after we load modules
947 enableAdaptation = Adaptation::Ecap::TheConfig.onoff || enableAdaptation;
948#endif
949 Adaptation::Config::Finalize(enableAdaptation);
950#endif
951
953#if ICAP_CLIENT
954 icapLogOpen();
955#endif
956 storeLogOpen();
957 Dns::Init();
958#if USE_SSL_CRTD
960#endif
961#if USE_OPENSSL
963#endif
964
966#if USE_AUTH
968#endif
970
971 if (IamPrimaryProcess()) {
972#if USE_WCCP
973
974 wccpInit();
975#endif
976#if USE_WCCPv2
977
978 wccp2Init();
979#endif
980 }
981
983
985
987
989
990 if (unlinkdNeeded())
991 unlinkdInit();
992
993#if USE_DELAY_POOLS
995#endif
996
997 reconfiguring = 0;
998}
999
1000static void
1002{
1003 if (AvoidSignalAction("log rotation", do_rotate))
1004 return;
1005
1006 icmpEngine.Close();
1008#if USE_AUTH
1010#endif
1012
1013 _db_rotate_log(); /* cache.log */
1015 storeLogRotate(); /* store.log */
1016 accessLogRotate(); /* access.log */
1018#if ICAP_CLIENT
1019 icapLogRotate(); /*icap.log*/
1020#endif
1021 icmpEngine.Open();
1022 redirectInit();
1023#if USE_AUTH
1025#endif
1027}
1028
1029static void
1031{
1033 leave_suid(); /* Run as non privilegied user */
1034#if _SQUID_OS2_
1035
1036 return;
1037#endif
1038
1039 if (geteuid() == 0) {
1040 debugs(0, DBG_CRITICAL, "Squid is not safe to run as root! If you must");
1041 debugs(0, DBG_CRITICAL, "start Squid as root, then you must configure");
1042 debugs(0, DBG_CRITICAL, "it to run as a non-priveledged user with the");
1043 debugs(0, DBG_CRITICAL, "'cache_effective_user' option in the config file.");
1044 fatal("Don't run Squid as root, set 'cache_effective_user'!");
1045 }
1046}
1047
1049static bool
1050mainChangeDir(const char *dir)
1051{
1052 if (chdir(dir) == 0)
1053 return true;
1054
1055 int xerrno = errno;
1056 debugs(50, DBG_CRITICAL, "ERROR: cannot change current directory to " << dir <<
1057 ": " << xstrerr(xerrno));
1058 return false;
1059}
1060
1063bool Chrooted = false;
1064
1066static void
1068{
1069 if (Config.chroot_dir && !Chrooted) {
1070 Chrooted = true;
1071
1072 if (chroot(Config.chroot_dir) != 0) {
1073 int xerrno = errno;
1074 fatalf("chroot to %s failed: %s", Config.chroot_dir, xstrerr(xerrno));
1075 }
1076
1077 if (!mainChangeDir("/"))
1078 fatalf("chdir to / after chroot to %s failed", Config.chroot_dir);
1079 }
1080
1081 if (Config.coredump_dir && strcmp("none", Config.coredump_dir) != 0) {
1083 debugs(0, Important(4), "Set Current Directory to " << Config.coredump_dir);
1084 return;
1085 }
1086 }
1087
1088 /* If we don't have coredump_dir or couldn't cd there, report current dir */
1089 char pathbuf[MAXPATHLEN];
1090 if (getcwd(pathbuf, MAXPATHLEN)) {
1091 debugs(0, DBG_IMPORTANT, "Current Directory is " << pathbuf);
1092 } else {
1093 int xerrno = errno;
1094 debugs(50, DBG_CRITICAL, "WARNING: Can't find current directory, getcwd: " << xstrerr(xerrno));
1095 }
1096}
1097
1098static void
1100{
1101 if (opt_catch_signals) {
1104 }
1105
1106 squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
1109
1111
1112 if (icpPortNumOverride != 1)
1113 Config.Port.icp = (unsigned short) icpPortNumOverride;
1114
1115 debugs(1, DBG_CRITICAL, "Starting Squid Cache version " << version_string << " for " << CONFIG_HOST_TYPE << "...");
1116 debugs(1, Critical(5), "Service Name: " << service_name);
1117
1118#if _SQUID_WINDOWS_
1119 if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
1120 debugs(1, DBG_CRITICAL, "Service command line is: " << WIN32_Service_Command_Line);
1121 } else
1122 debugs(1, DBG_CRITICAL, "Running on " << WIN32_OS_string);
1123#endif
1124
1125 debugs(1, Important(6), "Process ID " << getpid());
1126
1127 debugs(1, Important(7), "Process Roles:" << ProcessRoles());
1128
1130 debugs(1, Important(8), "With " << Squid_MaxFD << " file descriptors available");
1131
1132#if _SQUID_WINDOWS_
1133
1134 debugs(1, DBG_IMPORTANT, "With " << _getmaxstdio() << " CRT stdio descriptors available");
1135
1136 if (WIN32_Socks_initialized)
1137 debugs(1, DBG_IMPORTANT, "Windows sockets initialized");
1138
1139 if (WIN32_OS_version > _WIN_OS_WINNT) {
1141 }
1142
1143#endif
1144
1145 ipcache_init();
1146
1148
1149 parseEtcHosts();
1150
1151 Dns::Init();
1152
1153#if USE_SSL_CRTD
1155#endif
1156
1157#if USE_OPENSSL
1159#endif
1160
1161 redirectInit();
1162#if USE_AUTH
1164#endif
1166
1167 httpHeaderInitModule(); /* must go before any header processing (e.g. the one in errorInitialize) */
1168
1170
1171 accessLogInit();
1172
1174
1175#if ICAP_CLIENT
1176 icapLogOpen();
1177#endif
1178
1179#if SQUID_SNMP
1180
1181 snmpInit();
1182
1183#endif
1184#if MALLOC_DBG
1185
1186 malloc_debug(0, malloc_debug_level);
1187
1188#endif
1189
1190 if (unlinkdNeeded())
1191 unlinkdInit();
1192
1193 urlInitialize();
1194 statInit();
1195 storeInit();
1196 mainSetCwd();
1198 refreshInit();
1199#if USE_DELAY_POOLS
1201#endif
1202
1205
1207
1208 /* These use separate calls so that the comm loops can eventually
1209 * coexist.
1210 */
1211
1212 eventInit();
1213
1214 // TODO: pconn is a good candidate for new-style registration
1215 // PconnModule::GetInstance()->registerWithCacheManager();
1216 // moved to PconnModule::PconnModule()
1217
1218 if (IamPrimaryProcess()) {
1219#if USE_WCCP
1220 wccpInit();
1221
1222#endif
1223#if USE_WCCPv2
1224
1225 wccp2Init();
1226
1227#endif
1228 }
1229
1231
1233
1234 // neighborsRegisterWithCacheManager(); //moved to neighbors_init()
1235
1236 if (Config.chroot_dir)
1237 no_suid();
1238
1239#if defined(_SQUID_LINUX_THREADS_)
1240
1242
1244
1245#else
1246
1248
1250
1251#endif
1252
1254
1256
1257#ifdef SIGTTIN
1258
1260
1261#endif
1262
1263 memCheckInit();
1264
1265#if USE_LOADABLE_MODULES
1267#endif
1268
1269#if USE_ADAPTATION
1270 bool enableAdaptation = false;
1271
1272 // We can remove this dependency on specific adaptation mechanisms
1273 // if we create a generic Registry of such mechanisms. Should we?
1274#if ICAP_CLIENT
1276 enableAdaptation = Adaptation::Icap::TheConfig.onoff || enableAdaptation;
1277#endif
1278#if USE_ECAP
1279 Adaptation::Ecap::TheConfig.finalize(); // must be after we load modules
1280 enableAdaptation = Adaptation::Ecap::TheConfig.onoff || enableAdaptation;
1281#endif
1282 // must be the last adaptation-related finalize
1283 Adaptation::Config::Finalize(enableAdaptation);
1284#endif
1285
1286#if USE_DELAY_POOLS
1288#endif
1289
1290 eventAdd("storeMaintain", Store::Maintain, nullptr, 1.0, 1);
1291
1292 eventAdd("ipcache_purgelru", ipcache_purgelru, nullptr, 10.0, 1);
1293
1294 eventAdd("fqdncache_purgelru", fqdncache_purgelru, nullptr, 15.0, 1);
1295
1296 eventAdd("memPoolCleanIdlePools", Mem::CleanIdlePools, nullptr, 15.0, 1);
1297
1298 configured_once = 1;
1299}
1300
1301static void
1303{
1304 // ignore recursive calls to avoid termination loops
1305 static bool terminating = false;
1306 if (terminating)
1307 return;
1308 terminating = true;
1309
1310 debugs(1, DBG_CRITICAL, "FATAL: Dying after an undetermined failure" << CurrentExceptionExtra);
1311
1313 abort();
1314}
1315
1317int SquidMain(int argc, char **argv);
1319static int SquidMainSafe(int argc, char **argv);
1320
1321#if USE_WIN32_SERVICE
1322/* Entry point for Windows services */
1323extern "C" void WINAPI
1324SquidWinSvcMain(int argc, char **argv)
1325{
1326 SquidMainSafe(argc, argv);
1327}
1328#endif
1329
1330int
1331main(int argc, char **argv)
1332{
1333#if USE_WIN32_SERVICE
1334 SetErrorMode(SEM_NOGPFAULTERRORBOX);
1335 if ((argc == 2) && strstr(argv[1], _WIN_SQUID_SERVICE_OPTION))
1336 return WIN32_StartService(argc, argv);
1337 else {
1338 WIN32_run_mode = _WIN_SQUID_RUN_MODE_INTERACTIVE;
1339 opt_no_daemon = 1;
1340 }
1341#endif
1342
1343 return SquidMainSafe(argc, argv);
1344}
1345
1346static int
1347SquidMainSafe(int argc, char **argv)
1348{
1349 (void)std::set_terminate(&OnTerminate);
1350 // XXX: This top-level catch works great for startup, but, during runtime,
1351 // it erases valuable stack info. TODO: Let stack-preserving OnTerminate()
1352 // handle FATAL runtime errors by splitting main code into protected
1353 // startup, unprotected runtime, and protected termination sections!
1354 try {
1355 return SquidMain(argc, argv);
1356 } catch (...) {
1357 debugs(1, DBG_CRITICAL, "FATAL: " << CurrentException);
1358 }
1359 return EXIT_FAILURE;
1360}
1361
1363static void
1365{
1366 const char *kidParams = nullptr;
1367 if (cmdLine.hasOption(optKid, &kidParams)) {
1368 SBuf processName(kidParams);
1369 SBuf kidId;
1370 Parser::Tokenizer tok(processName);
1371 tok.suffix(kidId, CharacterSet::DIGIT);
1372 KidIdentifier = xatoi(kidId.c_str());
1373 tok.skipSuffix(SBuf("-"));
1374 TheKidName = tok.remaining();
1375 if (TheKidName.cmp("squid-coord") == 0)
1377 else if (TheKidName.cmp("squid") == 0)
1379 else if (TheKidName.cmp("squid-disk") == 0)
1381 else
1382 TheProcessKind = pkOther; // including coordinator
1383 } else {
1385 KidIdentifier = 0;
1386 }
1388}
1389
1391static void
1393{
1394 if (opt_no_daemon) {
1395 fd_open(0, FD_LOG, "stdin");
1396 fd_open(1, FD_LOG, "stdout");
1397 fd_open(2, FD_LOG, "stderr");
1398 }
1399 // we should not create cache.log outside chroot environment, if any
1400 // XXX: With Config.chroot_dir set, SMP master process calls Debug::BanCacheLogUse().
1401 if (!Config.chroot_dir || Chrooted)
1403 else
1405}
1406
1407static void
1409{
1412}
1413
1414static void
1416{
1417 setMaxFD();
1418 fde::Init();
1419 const auto skipCwdAdjusting = IamMasterProcess() && InDaemonMode();
1420 if (skipCwdAdjusting) {
1423 } else if (Config.chroot_dir) {
1425 enter_suid();
1426 // TODO: don't we need to RunConfigUsers() in the configured
1427 // chroot environment?
1428 mainSetCwd();
1429 leave_suid();
1431 } else {
1434 enter_suid();
1435 // TODO: since RunConfigUsers() may use a relative path, we
1436 // need to change the process root first
1437 mainSetCwd();
1438 leave_suid();
1439 }
1440}
1441
1443static void
1445{
1446 // These registration calls do not represent a RegisteredRunner "event". The
1447 // modules registered here should be initialized later, during those events.
1448
1449 // RegisteredRunner event handlers should not depend on handler call order
1450 // and, hence, should not depend on the registration call order below.
1451
1459 CallRunnerRegistratorIn(Dns, ConfigRr);
1460
1461#if HAVE_DISKIO_MODULE_IPCIO
1463#endif
1464
1465#if HAVE_AUTH_MODULE_NTLM
1467#endif
1468
1469#if USE_OPENSSL
1471#endif
1472
1473#if USE_SQUID_ESI && HAVE_LIBEXPAT
1474 CallRunnerRegistratorIn(Esi, ExpatRr);
1475#endif
1476
1477#if USE_SQUID_ESI && HAVE_LIBXML2
1478 CallRunnerRegistratorIn(Esi, Libxml2Rr);
1479#endif
1480
1481#if HAVE_FS_ROCK
1482 CallRunnerRegistratorIn(Rock, SwapDirRr);
1483#endif
1484}
1485
1486int
1487SquidMain(int argc, char **argv)
1488{
1489 // We must register all modules before the first RunRegisteredHere() call.
1490 // We do it ASAP/here so that we do not need to move this code when we add
1491 // earlier hooks to the RegisteredRunner API.
1493
1494 const CommandLine cmdLine(argc, argv, shortOpStr, squidOptions);
1495
1496 ConfigureCurrentKid(cmdLine);
1497
1498#if defined(SQUID_MAXFD_LIMIT)
1499
1502
1503#endif
1504
1505 /* NOP under non-windows */
1506 int WIN32_init_err=0;
1507 if ((WIN32_init_err = WIN32_Subsystem_Init(&argc, &argv)))
1508 return WIN32_init_err;
1509
1510 /* call mallopt() before anything else */
1511#if HAVE_MALLOPT
1512#ifdef M_GRAIN
1513 /* Round up all sizes to a multiple of this */
1514 mallopt(M_GRAIN, 16);
1515
1516#endif
1517#ifdef M_MXFAST
1518 /* biggest size that is considered a small block */
1519 mallopt(M_MXFAST, 256);
1520
1521#endif
1522#ifdef M_NBLKS
1523 /* allocate this many small blocks at once */
1524 mallopt(M_NLBLKS, 32);
1525
1526#endif
1527#endif /* HAVE_MALLOPT */
1528
1530
1532
1534
1535#if USE_WIN32_SERVICE
1536
1537 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1538
1539#endif
1540
1542
1545
1547 debugs(1, DBG_CRITICAL, "WARNING: --foreground command-line option has no effect with -N.");
1548 }
1549
1550#if USE_WIN32_SERVICE
1551
1552 if (opt_install_service) {
1554 return 0;
1555 }
1556
1557 if (opt_remove_service) {
1559 return 0;
1560 }
1561
1562 if (opt_command_line) {
1564 return 0;
1565 }
1566
1567#endif
1568
1569 /* parse configuration file
1570 * note: in "normal" case this used to be called from mainInitialize() */
1571 {
1572 int parse_err;
1573
1574 if (!ConfigFile)
1575 ConfigFile = xstrdup(DEFAULT_CONFIG_FILE);
1576
1578
1579 Mem::Init();
1580
1582
1583 storeFsInit(); /* required for config parsing */
1584
1585 Fs::Init();
1586
1587 /* May not be needed for parsing, have not audited for such */
1589
1590 /* we may want the parsing process to set this up in the future */
1591 Store::Init();
1592 Acl::Init();
1593 Auth::Init(); /* required for config parsing. NOP if !USE_AUTH */
1594 Ip::ProbeTransport(); // determine IPv4 or IPv6 capabilities before parsing.
1595
1596 Format::Token::Init(); // XXX: temporary. Use a runners registry of pre-parse runners instead.
1597
1599
1600 try {
1601 parse_err = parseConfigFile(ConfigFile);
1602 } catch (...) {
1603 // for now any errors are a fatal condition...
1604 debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file." <<
1605 (opt_parse_cfg_only ? " Run squid -k parse and check for errors." : ""));
1606 parse_err = 1;
1607 }
1608
1609 if (opt_parse_cfg_only || parse_err > 0)
1610 return parse_err;
1611 }
1613
1614 // Master optimization: Where possible, avoid pointless daemon fork() and/or
1615 // pointless wait for the exclusive PID file lock. This optional/weak check
1616 // is not applicable to kids because they always co-exist with their master.
1617 if (opt_send_signal == -1 && IamMasterProcess())
1619
1620 /* send signal to running copy and exit */
1621 if (opt_send_signal != -1) {
1622 /* chroot if configured to run inside chroot */
1623 mainSetCwd();
1624 if (Config.chroot_dir) {
1625 no_suid();
1626 } else {
1627 leave_suid();
1628 }
1629
1630 sendSignal();
1631 return 0;
1632 }
1633
1634 debugs(1,2, "Doing post-config initialization");
1635 leave_suid();
1637
1638 if (IamMasterProcess()) {
1639 if (InDaemonMode()) {
1640 watch_child(cmdLine);
1641 // NOTREACHED
1642 } else {
1644 }
1645 }
1646
1648 enter_suid();
1649
1652 debugs(0, DBG_CRITICAL, "Creating missing swap directories");
1653 Store::Root().create();
1654
1655 return 0;
1656 }
1657
1658 if (IamPrimaryProcess())
1661
1662 /* init comm module */
1663 comm_init();
1664
1665#if USE_WIN32_SERVICE
1666
1667 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1668
1669#endif
1670
1672
1673#if USE_WIN32_SERVICE
1674
1675 WIN32_svcstatusupdate(SERVICE_RUNNING, 0);
1676
1677#endif
1678
1679 /* main loop */
1680 EventLoop mainLoop;
1681
1682 SignalEngine signalEngine;
1683
1684 mainLoop.registerEngine(&signalEngine);
1685
1686 /* TODO: stop requiring the singleton here */
1688
1689 StoreRootEngine store_engine;
1690
1691 mainLoop.registerEngine(&store_engine);
1692
1693 CommSelectEngine comm_engine;
1694
1695 mainLoop.registerEngine(&comm_engine);
1696
1697 mainLoop.setPrimaryEngine(&comm_engine);
1698
1699 /* use the standard time service */
1700 Time::Engine time_engine;
1701
1702 mainLoop.setTimeService(&time_engine);
1703
1706 else if (UsingSmp() && (IamWorkerProcess() || IamDiskProcess()))
1708
1709 /* at this point we are finished the synchronous startup. */
1710 starting_up = 0;
1711
1712 mainLoop.run();
1713
1714 if (mainLoop.errcount == 10)
1715 fatal_dump("Event loop exited with failure.");
1716
1717 /* shutdown squid now */
1718 SquidShutdown();
1719
1720 /* NOTREACHED */
1721 return 0;
1722}
1723
1724static void
1726{
1727#if USE_WIN32_SERVICE
1728 // WIN32_sendSignal() does not need the PID value to signal,
1729 // but we must exit if there is no valid PID (TODO: Why?).
1730 (void)Instance::Other();
1731 if (!opt_signal_service)
1732 throw TexcHere("missing -n command line switch");
1734#else
1735 const auto pid = Instance::Other();
1736 if (kill(pid, opt_send_signal) &&
1737 /* ignore permissions if just running check */
1738 !(opt_send_signal == 0 && errno == EPERM)) {
1739 const auto savedErrno = errno;
1740 throw TexcHere(ToSBuf("failed to send signal ", opt_send_signal,
1741 " to Squid instance with PID ", pid, ": ", xstrerr(savedErrno)));
1742 }
1743#endif
1744 /* signal successfully sent */
1745}
1746
1747#if !_SQUID_WINDOWS_
1748/*
1749 * This function is run when Squid is in daemon mode, just
1750 * before the parent forks and starts up the child process.
1751 * It can be used for admin-specific tasks, such as notifying
1752 * someone that Squid is (re)started.
1753 */
1754static void
1755mainStartScript(const char *prog)
1756{
1757 char script[MAXPATHLEN];
1758 char *t;
1759 size_t sl = 0;
1760 pid_t cpid;
1761 pid_t rpid;
1762 xstrncpy(script, prog, MAXPATHLEN);
1763
1764 if ((t = strrchr(script, '/'))) {
1765 *(++t) = '\0';
1766 sl = strlen(script);
1767 }
1768
1769 xstrncpy(&script[sl], squid_start_script, MAXPATHLEN - sl);
1770
1771 if ((cpid = fork()) == 0) {
1772 /* child */
1773 execl(script, squid_start_script, (char *)nullptr);
1774 _exit(-1);
1775 } else {
1776 do {
1777 PidStatus status;
1778 rpid = WaitForOnePid(cpid, status, 0);
1779 } while (rpid != cpid);
1780 }
1781}
1782
1784static void
1786{
1787 if (AvoidSignalAction("shutdown", do_shutdown))
1788 return;
1789 debugs(1, 2, "received shutdown command");
1790 shutting_down = 1;
1791}
1792
1794static void
1796{
1797 if (AvoidSignalAction("reconfiguration", do_reconfigure))
1798 return;
1799 debugs(1, 2, "received reconfiguration command");
1800 reconfiguring = 1;
1802 // TODO: hot-reconfiguration of the number of kids, kids revival delay,
1803 // PID file location, etc.
1804}
1805
1807static void
1809{
1810 reconfiguring = 0;
1811}
1812
1814static void
1816{
1817 if (AvoidSignalAction("kids revival", do_revive_kids))
1818 return;
1819 debugs(1, 2, "woke up after ~" << Config.hopelessKidRevivalDelay << "s");
1820 // nothing to do here -- actual revival happens elsewhere in the main loop
1821 // the alarm was needed just to wake us up so that we do a loop iteration
1822}
1823
1824static void
1826{
1827 if (do_shutdown)
1829 if (do_reconfigure)
1831 if (do_revive_kids)
1833
1834 // emulate multi-step reconfiguration assumed by AvoidSignalAction()
1835 if (reconfiguring)
1837
1842 ReviveKidsSignal = -1; // alarms are not broadcasted
1843}
1844
1847static void
1849{
1850 const auto nextCheckDelay = TheKids.forgetOldFailures();
1851 assert(nextCheckDelay >= 0);
1852 (void)alarm(static_cast<unsigned int>(nextCheckDelay)); // resets or cancels
1853 if (nextCheckDelay)
1854 debugs(1, 2, "will recheck hopeless kids in " << nextCheckDelay << " seconds");
1855}
1856
1857static inline bool
1859{
1860 return (DebugSignal > 0 || RotateSignal > 0 || ReconfigureSignal > 0 ||
1861 ShutdownSignal > 0 || ReviveKidsSignal > 0);
1862}
1863
1865static void
1867{
1868 pid_t pid;
1869 if ((pid = fork()) < 0) {
1870 int xerrno = errno;
1871 throw TexcHere(ToSBuf("failed to fork(2) the master process: ", xstrerr(xerrno)));
1872 } else if (pid > 0) {
1873 // parent
1874 // The fork() effectively duped any saved debugs() messages. For
1875 // simplicity sake, let the child process deal with them.
1877 exit(EXIT_SUCCESS);
1878 }
1879 // child, running as a background daemon
1880 Must(setsid() > 0); // ought to succeed after fork()
1881}
1882
1883static void
1885{
1886 if (TheKids.someSignaled(SIGINT) || TheKids.someSignaled(SIGTERM)) {
1887 syslog(LOG_ALERT, "Exiting due to unexpected forced shutdown");
1888 exit(EXIT_FAILURE);
1889 }
1890
1891 if (TheKids.allHopeless()) {
1892 syslog(LOG_ALERT, "Exiting due to repeated, frequent failures");
1893 exit(EXIT_FAILURE);
1894 }
1895
1896 exit(EXIT_SUCCESS);
1897}
1898
1899#endif /* !_SQUID_WINDOWS_ */
1900
1901static void
1902watch_child(const CommandLine &masterCommand)
1903{
1904#if !_SQUID_WINDOWS_
1905 pid_t pid;
1906#ifdef TIOCNOTTY
1907
1908 int i;
1909#endif
1910
1911 int nullfd;
1912
1913 // TODO: zero values are not supported because they result in
1914 // misconfigured SMP Squid instances running forever, endlessly
1915 // restarting each dying kid.
1917 throw TexcHere("hopeless_kid_revival_delay must be positive");
1918
1919 enter_suid();
1920
1921 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1922
1923 if (!opt_foreground)
1925
1926 closelog();
1927
1928#ifdef TIOCNOTTY
1929
1930 if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
1931 ioctl(i, TIOCNOTTY, nullptr);
1932 close(i);
1933 }
1934
1935#endif
1936
1937 /*
1938 * RBCOLLINS - if cygwin stackdumps when squid is run without
1939 * -N, check the cygwin1.dll version, it needs to be AT LEAST
1940 * 1.1.3. execvp had a bit overflow error in a loop..
1941 */
1942 /* Connect stdio to /dev/null in daemon mode */
1943 nullfd = open(_PATH_DEVNULL, O_RDWR | O_TEXT);
1944
1945 if (nullfd < 0) {
1946 int xerrno = errno;
1947 fatalf(_PATH_DEVNULL " %s\n", xstrerr(xerrno));
1948 }
1949
1950 dup2(nullfd, 0);
1951
1952 if (!Debug::StderrEnabled()) {
1953 dup2(nullfd, 1);
1954 dup2(nullfd, 2);
1955 }
1956
1957 leave_suid();
1960 enter_suid();
1961
1962#if defined(_SQUID_LINUX_THREADS_)
1963 squid_signal(SIGQUIT, rotate_logs, 0);
1964 squid_signal(SIGTRAP, sigusr2_handle, 0);
1965#else
1966 squid_signal(SIGUSR1, rotate_logs, 0);
1967 squid_signal(SIGUSR2, sigusr2_handle, 0);
1968#endif
1969
1970 squid_signal(SIGHUP, reconfigure, 0);
1971
1972 squid_signal(SIGTERM, master_shutdown, 0);
1973 squid_signal(SIGALRM, master_revive_kids, 0);
1974 squid_signal(SIGINT, master_shutdown, 0);
1975#ifdef SIGTTIN
1976 squid_signal(SIGTTIN, master_shutdown, 0);
1977#endif
1978
1979 if (Config.workers > 128) {
1980 syslog(LOG_ALERT, "Suspiciously high workers value: %d",
1981 Config.workers);
1982 // but we keep going in hope that user knows best
1983 }
1984 TheKids.init();
1985
1986 configured_once = 1;
1987
1988 syslog(LOG_NOTICE, "Squid Parent: will start %d kids", (int)TheKids.count());
1989
1990 // keep [re]starting kids until it is time to quit
1991 for (;;) {
1992 bool mainStartScriptCalled = false;
1993 // start each kid that needs to be [re]started; once
1994 for (int i = TheKids.count() - 1; i >= 0 && !shutting_down; --i) {
1995 Kid& kid = TheKids.get(i);
1996 if (!kid.shouldRestart())
1997 continue;
1998
1999 if (!mainStartScriptCalled) {
2000 mainStartScript(masterCommand.arg0());
2001 mainStartScriptCalled = true;
2002 }
2003
2004 // These are only needed by the forked child below, but let's keep
2005 // them out of that "no man's land" between fork() and execvp().
2006 auto kidCommand = masterCommand;
2007 kidCommand.resetArg0(kid.processName().c_str());
2008 assert(!kidCommand.hasOption(optKid));
2009 kidCommand.pushFrontOption("--kid", kid.gist().c_str());
2010
2011 if ((pid = fork()) == 0) {
2012 /* child */
2013 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
2014 (void)execvp(masterCommand.arg0(), kidCommand.argv());
2015 int xerrno = errno;
2016 syslog(LOG_ALERT, "execvp failed: %s", xstrerr(xerrno));
2017 }
2018
2019 kid.start(pid);
2020 syslog(LOG_NOTICE, "Squid Parent: %s process %d started",
2021 kid.processName().c_str(), pid);
2022 }
2023
2024 /* parent */
2025 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
2026
2027 // If Squid received a signal while checking for dying kids (below) or
2028 // starting new kids (above), then do a fast check for a new dying kid
2029 // (WaitForAnyPid with the WNOHANG option) and continue to forward
2030 // signals to kids. Otherwise, wait for a kid to die or for a signal
2031 // to abort the blocking WaitForAnyPid() call.
2032 // With the WNOHANG option, we could check whether WaitForAnyPid() was
2033 // aborted by a dying kid or a signal, but it is not required: The
2034 // next do/while loop will check again for any dying kids.
2035 int waitFlag = 0;
2036 if (masterSignaled())
2037 waitFlag = WNOHANG;
2038 PidStatus status;
2039 pid = WaitForAnyPid(status, waitFlag);
2041
2042 // check for a stopped kid
2043 if (Kid *kid = pid > 0 ? TheKids.find(pid) : nullptr)
2044 kid->stop(status);
2045 else if (pid > 0)
2046 syslog(LOG_NOTICE, "Squid Parent: unknown child process %d exited", pid);
2047
2050
2052 leave_suid();
2053 // XXX: Master process has no main loop and, hence, should not call
2054 // RegisteredRunner::startShutdown which promises a loop iteration.
2056 enter_suid();
2057 masterExit();
2058 }
2059 }
2060
2061 /* NOTREACHED */
2062#endif /* _SQUID_WINDOWS_ */
2063
2064}
2065
2066static void
2068{
2069 /* XXX: This function is called after the main loop has quit, which
2070 * means that no AsyncCalls would be called, including close handlers.
2071 * TODO: We need to close/shut/free everything that needs calls before
2072 * exiting the loop.
2073 */
2074
2075#if USE_WIN32_SERVICE
2076 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2077#endif
2078
2079 debugs(1, Important(9), "Shutting down...");
2080#if USE_SSL_CRTD
2082#endif
2083#if USE_OPENSSL
2085#endif
2088 icpClosePorts();
2089#if USE_HTCP
2091#endif
2092#if SQUID_SNMP
2094#endif
2095#if USE_WCCP
2096
2098#endif
2099#if USE_WCCPv2
2100
2102#endif
2103
2106
2107#if USE_DELAY_POOLS
2109#endif
2110#if USE_AUTH
2112#endif
2113#if USE_WIN32_SERVICE
2114
2115 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2116#endif
2117#if ICAP_CLIENT
2119#endif
2120
2121 Store::Root().sync(); /* Flush pending object writes/unlinks */
2122
2123 unlinkdClose(); /* after sync/flush. NOP if !USE_UNLINKD */
2124
2126 PrintRusage();
2128 Store::Root().sync(); /* Flush log writes */
2129 storeLogClose();
2131 Store::Root().sync(); /* Flush log close */
2133
2134 fdDumpOpen();
2135
2136 comm_exit();
2137
2139
2140 memClean();
2141
2142 debugs(1, Important(10), "Squid Cache (Version " << version_string << "): Exiting normally.");
2143
2144 exit(shutdown_status);
2145}
2146
void accessLogInit(void)
Definition: access_log.cc:313
void accessLogClose(void)
Definition: access_log.cc:159
void accessLogRotate(void)
Definition: access_log.cc:145
void CpuAffinityInit()
set CPU affinity for this process on startup
Definition: CpuAffinity.cc:26
void CpuAffinityCheck()
check CPU affinity configuration and print warnings if needed
Definition: CpuAffinity.cc:49
void CpuAffinityReconfigure()
reconfigure CPU affinity for this process
Definition: CpuAffinity.cc:38
void storeDirOpenSwapLogs()
Definition: Disks.cc:676
int storeDirWriteCleanLogs(int reopen)
Definition: Disks.cc:699
void storeDirCloseSwapLogs()
Definition: Disks.cc:683
void httpHeaderInitModule(void)
Definition: HttpHeader.cc:121
IcmpSquid icmpEngine
Definition: IcmpSquid.cc:26
static pid_t pid
Definition: IcmpSquid.cc:34
int TheProcessKind
ProcessKind for the current process.
Definition: Kid.cc:21
@ pkWorker
general-purpose worker bee
Definition: Kid.h:105
@ pkCoordinator
manages all other kids
Definition: Kid.h:104
@ pkDisker
cache_dir manager
Definition: Kid.h:106
@ pkOther
we do not know or do not care
Definition: Kid.h:103
SBuf TheKidName
current Squid process name (e.g., "squid-coord")
Definition: Kids.cc:19
Kids TheKids
All kids being maintained.
Definition: Kids.cc:18
void LoadableModulesConfigure(const wordlist *names)
int xatoi(const char *token)
Definition: Parsing.cc:44
#define RunRegisteredHere(m)
convenience macro to describe/debug the caller and the method being called
#define CallRunnerRegistratorIn(Namespace, ClassName)
#define CallRunnerRegistrator(ClassName)
#define SQUIDSBUFPH
Definition: SBuf.h:31
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
class SquidConfig Config
Definition: SquidConfig.cc:12
class SquidConfig2 Config2
Definition: SquidConfig.cc:14
StatCounters statCounter
Definition: StatCounters.cc:12
std::ostream & CurrentExceptionExtra(std::ostream &os)
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:63
#define Must(condition)
Definition: TextException.h:75
void urlInitialize(void)
Definition: Uri.cc:138
void WIN32_SetServiceCommandLine()
Definition: WinSvc.cc:704
int WIN32_StartService(int argc, char **argv)
Definition: WinSvc.cc:894
int WIN32_Subsystem_Init(int *argc, char ***argv)
Definition: WinSvc.cc:459
void WIN32_RemoveService()
Definition: WinSvc.cc:648
void WIN32_InstallService()
Definition: WinSvc.cc:719
DWORD WIN32_IpAddrChangeMonitorInit()
Definition: WinSvc.cc:441
void WIN32_sendSignal(int WIN32_signal)
Definition: WinSvc.cc:799
#define assert(EX)
Definition: assert.h:17
void authenticateInit(Auth::ConfigVector *config)
Definition: Gadgets.cc:70
void authenticateReset(void)
Definition: Gadgets.cc:94
void authenticateRotate(void)
Definition: Gadgets.cc:85
int parseConfigFile(const char *file_name)
Definition: cache_cf.cc:635
void add_http_port(char *portspec)
Definition: cache_cf.cc:3716
void self_destruct(void)
Definition: cache_cf.cc:277
void carpInit(void)
Definition: carp.cc:51
static void Initialize()
Definition: Acl.cc:438
virtual bool finalize()
Definition: Config.cc:184
static void Finalize(bool enable)
Definition: Config.cc:230
void freeService(void)
Definition: Config.cc:146
bool finalize() override
Definition: Config.cc:27
static void Init()
initializes down-cased protocol scheme names array
Definition: UriScheme.cc:38
static void Start(const Pointer &job)
Definition: AsyncJob.cc:37
static void RegisterWithCacheManager()
Definition: AsyncJob.cc:215
static void FreeAll()
Definition: Scheme.cc:60
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:18
static const CharacterSet DIGIT
Definition: CharacterSet.h:84
static const CharacterSet ALPHA
Definition: CharacterSet.h:76
void finalize()
checks pools configuration
initializes shared queue used by CollapsedForwarding
Manages arguments passed to a program (i.e., main(argc, argv) parameters).
Definition: CommandLine.h:35
bool hasOption(const int optId, const char **optValue=nullptr) const
Definition: CommandLine.cc:71
void forEachOption(Visitor) const
calls Visitor for each of the configured command line option
Definition: CommandLine.cc:89
void resetArg0(const char *programName)
replaces argv[0] with the new value
Definition: CommandLine.cc:115
const char * arg0() const
Definition: CommandLine.h:58
static void ResetStderrLevel(int maxLevel)
Definition: debug.cc:700
static bool StderrEnabled()
Definition: debug.cc:726
static void parseOptions(char const *)
Definition: debug.cc:1092
static void PrepareToDie()
Definition: debug.cc:562
static void ForgetSaved()
silently erases saved early debugs() messages (if any)
Definition: debug.cc:553
static void NameThisKid(int kidIdentifier)
Definition: debug.cc:406
static int override_X
Definition: Stream.h:84
static void SettleSyslog()
Definition: debug.cc:1142
static void UseCacheLog()
Definition: debug.cc:1122
static void BanCacheLogUse()
Definition: debug.cc:1115
static void ConfigureSyslog(const char *facility)
enables logging to syslog (using the specified facility, when not nil)
Definition: debug.cc:1080
static void EnsureDefaultStderrLevel(int maxDefault)
Definition: debug.cc:692
static void SettleStderr()
Definition: debug.cc:706
static void FreePools()
Definition: delay_pools.cc:555
static void Init()
Definition: delay_pools.cc:458
static void FreeAllModules()
static void SetupAllModules()
Definition: DiskIOModule.cc:45
int errcount
Definition: EventLoop.h:69
void run()
Definition: EventLoop.cc:76
static EventLoop * Running
Definition: EventLoop.h:73
void setTimeService(Time::Engine *)
Definition: EventLoop.cc:162
void registerEngine(AsyncEngine *engine)
Definition: EventLoop.cc:70
void stop()
Definition: EventLoop.cc:168
void setPrimaryEngine(AsyncEngine *engine)
Definition: EventLoop.cc:149
static EventScheduler * GetInstance()
Definition: event.cc:294
static void Init()
Initialize the format token registrations.
Definition: Token.cc:253
static void initModule()
Definition: FwdState.cc:1385
void Close() override
Shutdown pinger helper and control channel.
Definition: IcmpSquid.cc:254
int Open() override
Start pinger helper and initiate control channel.
Definition: IcmpSquid.cc:189
static Coordinator * Instance()
Definition: Coordinator.cc:291
Receives coordination messages on behalf of its process or thread.
Definition: Strand.h:28
Definition: Kid.h:18
void start(pid_t cpid)
called when this kid got started, records PID
Definition: Kid.cc:34
SBuf processName() const
returns kid name
Definition: Kid.cc:163
SBuf gist() const
Definition: Kid.cc:171
bool shouldRestart() const
returns true if master should restart this kid
Definition: Kid.cc:97
void forgetAllFailures()
forgets all failures in all kids
Definition: Kids.cc:77
bool someSignaled(const int sgnl) const
whether some kids died from a given signal
Definition: Kids.cc:116
size_t count() const
returns the number of kids
Definition: Kids.cc:146
Kid * find(pid_t pid)
returns kid by pid
Definition: Kids.cc:47
bool shouldRestartSome() const
whether some kids should be restarted by master
Definition: Kids.cc:136
void init()
initialize all kid records based on Config
Definition: Kids.cc:26
bool someRunning() const
whether some kids are running
Definition: Kids.cc:126
Kid & get(size_t i)
returns the kid by index, useful for kids iteration
Definition: Kids.cc:60
time_t forgetOldFailures()
Definition: Kids.cc:84
bool allHopeless() const
whether all kids are hopeless
Definition: Kids.cc:67
launches PeerPoolMgrs for peers configured with standby.limit
Definition: PeerPoolMgr.cc:236
virtual void syncConfig()
virtual void bootstrapConfig()
virtual void claimMemoryNeeds()
virtual void startShutdown()
virtual void finalizeConfig()
virtual void endingShutdown()
virtual void finishShutdown()
Meant for cleanup of services needed by the already destroyed objects.
virtual void useConfig()
virtual void startReconfigure()
static void RegisterWithCacheManager(void)
Definition: SBuf.h:94
const char * c_str()
Definition: SBuf.cc:516
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:415
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:275
SBuf & assign(const SBuf &S)
Definition: SBuf.cc:83
initializes shared memory pages
Definition: Pages.cc:93
initializes shared memory segments used by MemStore
Definition: Session.cc:412
void doShutdown(time_t wait)
Definition: main.cc:270
int checkEvents(int timeout) override
Definition: main.cc:225
static void FinalShutdownRunners(void *)
Definition: main.cc:208
void handleStoppedChild()
Definition: main.cc:299
static void StopEventLoop(void *)
Definition: main.cc:203
struct SquidConfig2::@120 onoff
struct SquidConfig::@94 Port
char * mimeTablePathname
Definition: SquidConfig.h:226
wordlist * loadable_module_names
Definition: SquidConfig.h:522
ClientDelayConfig ClientDelay
Definition: SquidConfig.h:446
char * coredump_dir
Definition: SquidConfig.h:472
time_t shutdownLifetime
Definition: SquidConfig.h:107
char * chroot_dir
Definition: SquidConfig.h:473
unsigned short icp
Definition: SquidConfig.h:141
time_t hopelessKidRevivalDelay
hopeless_kid_revival_delay
Definition: SquidConfig.h:109
static void Shutdown()
Shutdown helper structure.
Definition: helper.cc:232
static void Init()
Init helper structure.
Definition: helper.cc:171
static void Reconfigure()
Definition: helper.cc:248
void reconfigureStart()
When reconfigring should be called this method.
static void Init()
Init helper structure.
Definition: helper.cc:77
static void Reconfigure()
Definition: helper.cc:118
static void Shutdown()
Shutdown helper structure.
Definition: helper.cc:108
struct StatCounters::@122 client_http
int checkEvents(int) override
Definition: main.cc:190
void sync() override
prepare for shutdown
Definition: Controller.cc:218
void create() override
create system resources needed for this store to operate in the future
Definition: Controller.cc:78
int callback() override
called once every main loop iteration; TODO: Move to UFS code.
Definition: Controller.cc:229
event class for doing synthetic time etc
Definition: Engine.h:16
initializes shared memory segment used by Transients
Definition: Transients.cc:383
static void Init()
Definition: fde.cc:141
void clientOpenListenSockets(void)
void clientConnectionsClose()
void fd_open(const int fd, unsigned int, const char *description)
Definition: minimal.cc:14
void comm_init(void)
Definition: comm.cc:1166
void comm_exit(void)
Definition: comm.cc:1189
void commCloseAllSockets(void)
Definition: comm.cc:1470
void(* failure_notify)(const char *)
Definition: compat.cc:12
#define SA_RESTART
#define SA_RESETHAND
#define SQUID_MAXFD_LIMIT
Definition: compat_shared.h:66
#define SA_NODEFER
#define Critical(id)
Definition: Messages.h:92
#define Important(id)
Definition: Messages.h:93
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
#define O_TEXT
Definition: defines.h:133
static int port
Definition: ldap_backend.cc:70
@ FD_LOG
Definition: enums.h:14
void eventInit(void)
Definition: event.cc:133
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:107
void externalAclInit(void)
void externalAclShutdown(void)
void fatal(const char *message)
Definition: fatal.cc:28
void fatal_dump(const char *message)
Definition: fatal.cc:78
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
void fdDumpOpen(void)
Definition: fd.cc:242
char * ConfigFile
int opt_reload_hit_only
int opt_send_signal
int opt_store_doublecheck
struct timeval squid_start
int opt_create_swap_dirs
int opt_reuseaddr
int opt_no_daemon
int opt_foreground
int shutting_down
const char * version_string
int Squid_MaxFD
int opt_foreground_rebuild
int opt_parse_cfg_only
int opt_catch_signals
int starting_up
int reconfiguring
int KidIdentifier
void asnFreeMemory(void)
Definition: Asn.cc:206
void asnInit(void)
Definition: Asn.cc:190
void errorInitialize(void)
Definition: errorpage.cc:254
void errorClean(void)
Definition: errorpage.cc:316
void fqdncache_init(void)
Definition: fqdncache.cc:685
void fqdncache_purgelru(void *)
Definition: fqdncache.cc:200
void fqdncache_restart(void)
Definition: fqdncache.cc:620
void ipcache_restart(void)
Definition: ipcache.cc:1102
void ipcache_init(void)
Definition: ipcache.cc:695
void ipcache_purgelru(void *)
Definition: ipcache.cc:352
void icpConnectionShutdown(void)
Definition: icp_v2.cc:779
void icpOpenPorts(void)
Definition: icp_v2.cc:697
void icpClosePorts(void)
Definition: icp_v2.cc:804
void htcpOpenPorts(void)
Definition: htcp.cc:1442
void htcpSocketShutdown(void)
Definition: htcp.cc:1616
void htcpClosePorts(void)
Definition: htcp.cc:1645
void icapLogClose()
Definition: icap_log.cc:38
void icapLogRotate()
Definition: icap_log.cc:51
void icapLogOpen()
Definition: icap_log.cc:23
static void setEffectiveUser(void)
Definition: main.cc:1030
static void master_shutdown(int sig)
Shutdown signal handler for master process.
Definition: main.cc:742
static void StartUsingConfig()
Definition: main.cc:1415
static void watch_child(const CommandLine &)
Definition: main.cc:1902
void WINAPI WIN32_svcHandler(DWORD)
Definition: WinSvc.cc:578
static volatile int do_reconfigure
Definition: main.cc:150
static void mainReconfigureStart(void)
Definition: main.cc:852
static void ConfigureDebugging()
Start directing debugs() messages to the configured cache.log.
Definition: main.cc:1392
static int opt_signal_service
Definition: main.cc:143
int SquidMain(int argc, char **argv)
unsafe main routine – may throw
Definition: main.cc:1487
static void masterReviveKids()
Reacts to the kid revival alarm.
Definition: main.cc:1815
static int opt_command_line
Definition: main.cc:138
static int ReviveKidsSignal
Definition: main.cc:160
static volatile int do_handle_stopped_child
Definition: main.cc:155
static void RegisterModules()
register all known modules for handling future RegisteredRunner events
Definition: main.cc:1444
static void GoIntoBackground()
makes the caller a daemon process running in the background
Definition: main.cc:1866
int main(int argc, char **argv)
Definition: main.cc:1331
static struct option squidOptions[]
Definition: main.cc:400
static volatile int do_revive_kids
Definition: main.cc:153
static void mainSetCwd(void)
set the working directory.
Definition: main.cc:1067
@ optKid
Definition: main.cc:387
@ optForeground
Definition: main.cc:386
static void ConfigureCurrentKid(const CommandLine &cmdLine)
computes name and ID for the current kid process
Definition: main.cc:1364
static volatile int do_shutdown
Definition: main.cc:152
void rotate_logs(int sig)
Definition: main.cc:701
static void RunConfigUsers()
Definition: main.cc:1408
void sig_child(int sig)
Definition: main.cc:771
static int configured_once
Definition: main.cc:146
static void mainHandleCommandLineOption(const int optId, const char *optValue)
Definition: main.cc:410
static int opt_remove_service
Definition: main.cc:137
static void master_revive_kids(int sig)
Definition: main.cc:728
static void SquidShutdown(void)
Definition: main.cc:2067
void WINAPI SquidWinSvcMain(int argc, char **argv)
Definition: main.cc:1324
static void masterShutdownStart()
Initiates shutdown sequence. Shutdown ends when the last running kids stops.
Definition: main.cc:1785
static bool mainChangeDir(const char *dir)
changes working directory, providing error reporting
Definition: main.cc:1050
static void masterExit()
Definition: main.cc:1884
static void OnTerminate()
Definition: main.cc:1302
static int RotateSignal
Definition: main.cc:157
static int SquidMainSafe(int argc, char **argv)
unsafe main routine wrapper to catch exceptions
Definition: main.cc:1347
static int ReconfigureSignal
Definition: main.cc:158
static int ShutdownSignal
Definition: main.cc:159
static void mainReconfigureFinish(void *)
Definition: main.cc:888
void WIN32_svcstatusupdate(DWORD, DWORD)
Definition: WinSvc.cc:567
static void sendSignal(void)
Definition: main.cc:1725
static const char * squid_start_script
Definition: main.cc:177
static int icpPortNumOverride
Definition: main.cc:145
static void serverConnectionsOpen(void)
Definition: main.cc:783
static const char * shortOpStr
Definition: main.cc:393
static void masterCheckAndBroadcastSignals()
Definition: main.cc:1825
static volatile int shutdown_status
Definition: main.cc:154
static void masterMaintainKidRevivalSchedule()
Definition: main.cc:1848
bool Chrooted
Definition: main.cc:1063
static void mainStartScript(const char *prog)
Definition: main.cc:1755
static int opt_install_service
Definition: main.cc:136
void reconfigure(int sig)
Definition: main.cc:715
static void masterReconfigureFinish()
Ends reconfiguration sequence started by masterReconfigureStart().
Definition: main.cc:1808
static void mainRotate(void)
Definition: main.cc:1001
static void usage(void)
Definition: main.cc:325
static void masterReconfigureStart()
Initiates reconfiguration sequence. See also: masterReconfigureFinish().
Definition: main.cc:1795
static bool AvoidSignalAction(const char *description, volatile int &signalVar)
Definition: main.cc:241
static volatile int do_rotate
Definition: main.cc:151
static void serverConnectionsClose(void)
Definition: main.cc:821
static bool masterSignaled()
Definition: main.cc:1858
void shut_down(int sig)
Definition: main.cc:756
static void mainInitialize(void)
Definition: main.cc:1099
static char * opt_syslog_facility
Definition: main.cc:144
void memClean(void)
Main cleanup handler.
Definition: old_api.cc:485
void memCheckInit(void)
Definition: old_api.cc:471
void mimeInit(char *filename)
Definition: mime.cc:235
void Init(void)
prepares to parse ACLs configuration
Definition: AclRegs.cc:191
Config TheConfig
Definition: Config.cc:16
Config TheConfig
Definition: Config.cc:19
void Init(void)
Initialize Auth subsystem.
Definition: AuthReg.cc:31
Auth::Config TheConfig
Definition: Config.cc:15
generic DNS API
Definition: forward.h:20
void Init(void)
ESI protocol types and operators.
Definition: Element.h:89
void Init()
Definition: Module.cc:33
void WriteOurPid()
creates a PID file; throws on error
Definition: Instance.cc:186
void ThrowIfAlreadyRunning()
Definition: Instance.cc:139
pid_t Other()
Definition: Instance.cc:128
void ProbeTransport(void)
Probe to discover IPv6 capabilities.
void Init()
Definition: old_api.cc:425
void CleanIdlePools(void *unused)
Definition: old_api.cc:399
Definition: forward.h:28
void OpenLogs()
opens logs enabled in the current configuration
Definition: KeyLog.cc:71
void CloseLogs()
closes logs opened by OpenLogs()
Definition: KeyLog.cc:85
void RotateLogs()
rotates logs opened by OpenLogs()
Definition: KeyLog.cc:78
GlobalContextStorage TheGlobalContextStorage
Global cache for store all SSL server certificates.
Controller & Root()
safely access controller singleton
Definition: Controller.cc:938
void Maintain(void *unused)
Definition: store.cc:1118
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:945
#define xfree
#define xstrdup
void neighbors_init(void)
Definition: neighbors.cc:510
void netdbInit(void)
Definition: net_db.cc:803
#define OPENSSL_VERSION
Definition: openssl.h:133
#define OpenSSL_version
Definition: openssl.h:134
void peerSelectInit(void)
Definition: peer_select.cc:922
void peerSourceHashInit(void)
void peerUserHashInit(void)
void redirectInit(void)
Definition: redirect.cc:333
void redirectReconfigure()
Definition: redirect.cc:433
void redirectShutdown(void)
Definition: redirect.cc:406
void refreshInit(void)
Definition: refresh.cc:754
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63
void snmpInit(void)
Definition: snmp_core.cc:71
void snmpOpenPorts(void)
Definition: snmp_core.cc:259
void snmpClosePorts(void)
Definition: snmp_core.cc:323
#define CACHE_ICP_PORT
Definition: squid.h:17
#define CACHE_HTTP_PORT
Definition: squid.h:16
void _db_rotate_log(void)
Definition: debug.cc:1157
void statInit(void)
Definition: stat.cc:1248
#define TRUE
Definition: std-includes.h:55
#define FALSE
Definition: std-includes.h:56
#define MAXPATHLEN
Definition: stdio.h:62
void storeInit(void)
Definition: store.cc:1243
void storeFsInit(void)
Definition: store.cc:1622
void storeLogClose(void)
Definition: store_log.cc:105
void storeLogOpen(void)
Definition: store_log.cc:123
void storeLogRotate(void)
Definition: store_log.cc:96
Definition: parse.c:160
time_t getCurrentTime() STUB_RETVAL(0) int tvSubUsec(struct timeval
bool IamWorkerProcess()
whether the current process handles HTTP transactions and such
Definition: stub_tools.cc:47
bool SIGHDLR int STUB void const char void ObjPackMethod STUB void const char *STUB void keepCapabilities(void) STUB pid_t WaitForOnePid(pid_t
SBuf service_name(APP_SHORTNAME)
void releaseServerSockets(void) STUB_NOP void dumpMallocStats(void) STUB void squid_getrusage(struct rusage *) STUB double rusage_cputime(struct rusage *) STUB_RETVAL(0) int rusage_maxrss(struct rusage *) STUB_RETVAL(0) int rusage_pagefaults(struct rusage *) STUB_RETVAL(0) void PrintRusage(void) STUB void death(int) STUB void BroadcastSignalIfAny(int &) STUB void sigusr2_handle(int) STUB void debug_trap(const char *) STUB void sig_child(int) STUB const char *getMyHostname(void) STUB_RETVAL(nullptr) const char *uniqueHostname(void) STUB_RETVAL(nullptr) void leave_suid(void) STUB_NOP void enter_suid(void) STUB void no_suid(void) STUB bool IamMasterProcess()
Definition: stub_tools.cc:18
bool IamDiskProcess() STUB_RETVAL_NOP(false) bool InDaemonMode() STUB_RETVAL_NOP(false) bool UsingSmp() STUB_RETVAL_NOP(false) bool IamCoordinatorProcess() STUB_RETVAL(false) bool IamPrimaryProcess() STUB_RETVAL(false) int NumberOfKids() STUB_RETVAL(0) void setMaxFD(void) STUB void setSystemLimits(void) STUB void squid_signal(int
whether the current process is dedicated to managing a cache_dir
int DebugSignal
Definition: stub_tools.cc:16
bool SIGHDLR int STUB void const char void ObjPackMethod STUB void parseEtcHosts(void) STUB int getMyPort(void) STUB_RETVAL(0) void setUmask(mode_t) STUB void strwordquote(MemBuf *
void wccp2Init(void) STUB void wccp2ConnectionOpen(void) STUB void wccp2ConnectionClose(void) STUB void dump_wccp2_method(StoreEntry *
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17
void leave_suid(void)
Definition: tools.cc:559
bool IamMasterProcess()
whether the current process is the parent of all other Squid processes
Definition: tools.cc:668
bool InDaemonMode()
Whether we are running in daemon mode.
Definition: tools.cc:690
void squid_signal(int sig, SIGHDLR *func, int flags)
Definition: tools.cc:873
pid_t WaitForOnePid(pid_t pid, PidStatus &status, int flags)
Definition: tools.cc:1180
void setUmask(mode_t mask)
Definition: tools.cc:1069
void death(int sig)
Definition: tools.cc:345
void sigusr2_handle(int sig)
Definition: tools.cc:433
void setMaxFD(void)
Definition: tools.cc:762
bool IamPrimaryProcess()
Definition: tools.cc:708
void no_suid(void)
Definition: tools.cc:646
void PrintRusage(void)
Definition: tools.cc:329
void enter_suid(void)
Definition: tools.cc:623
void BroadcastSignalIfAny(int &sig)
Definition: tools.cc:418
bool IamCoordinatorProcess()
whether the current process coordinates worker processes
Definition: tools.cc:702
void dumpMallocStats(void)
Definition: tools.cc:166
bool UsingSmp()
Whether there should be more than one worker process running.
Definition: tools.cc:696
SBuf ProcessRoles()
a string describing this process roles such as worker or coordinator
Definition: tools.cc:739
void setSystemLimits(void)
Definition: tools.cc:811
int PidStatus
Definition: tools.h:91
pid_t WaitForAnyPid(PidStatus &status, int flags)
Definition: tools.h:107
bool unlinkdNeeded(void)
Definition: unlinkd.cc:180
void unlinkdClose(void)
Definition: unlinkd.cc:133
void unlinkdInit(void)
Definition: unlinkd.cc:193
#define APP_SHORTNAME
Definition: version.h:22
void wccp2ConnectionOpen(void)
Definition: wccp2.cc:952
void wccp2ConnectionClose(void)
Definition: wccp2.cc:1040
void wccpConnectionClose(void)
Definition: wccp.cc:161
void wccpConnectionOpen(void)
Definition: wccp.cc:109
void wccpInit(void)
Definition: wccp.cc:91
const char * xstrerr(int error)
Definition: xstrerror.cc:83
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors