main.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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) {
192 return EVENT_IDLE;
193 };
194};
195
197{
198
199public:
200#if KILL_PARENT_OPT
201 SignalEngine(): parentKillNotified(false) {
202 parentPid = getppid();
203 }
204#endif
205
206 virtual int checkEvents(int timeout);
207
208private:
209 static void StopEventLoop(void *) {
212 }
213
214 static void FinalShutdownRunners(void *) {
216
217 // XXX: this should be a Runner.
218#if USE_AUTH
219 /* detach the auth components (only do this on full shutdown) */
221#endif
222
223 eventAdd("SquidTerminate", &StopEventLoop, nullptr, 0, 1, false);
224 }
225
226 void doShutdown(time_t wait);
227 void handleStoppedChild();
228
229#if KILL_PARENT_OPT
230 bool parentKillNotified;
231 pid_t parentPid;
232#endif
233};
234
235int
237{
238 if (do_reconfigure)
240 else if (do_rotate)
241 mainRotate();
242 else if (do_shutdown)
246 return EVENT_IDLE;
247}
248
251static bool
252AvoidSignalAction(const char *description, volatile int &signalVar)
253{
254 const char *avoiding = "delaying";
255 const char *currentEvent = "none";
256 if (shutting_down) {
257 currentEvent = "shutdown";
258 avoiding = "canceling";
259 // do not avoid repeated shutdown signals
260 // which just means the user wants to skip/abort shutdown timeouts
261 if (strcmp(currentEvent, description) == 0)
262 return false;
263 signalVar = 0;
264 }
265 else if (!configured_once)
266 currentEvent = "startup";
267 else if (reconfiguring)
268 currentEvent = "reconfiguration";
269 else {
270 signalVar = 0;
271 return false; // do not avoid (i.e., execute immediately)
272 // the caller may produce a signal-specific debugging message
273 }
274
275 debugs(1, DBG_IMPORTANT, avoiding << ' ' << description <<
276 " request during " << currentEvent);
277 return true;
278}
279
280void
282{
283 if (AvoidSignalAction("shutdown", do_shutdown))
284 return;
285
286 debugs(1, Important(2), "Preparing for shutdown after " << statCounter.client_http.requests << " requests");
287 debugs(1, Important(3), "Waiting " << wait << " seconds for active connections to finish");
288
289#if KILL_PARENT_OPT
290 if (!IamMasterProcess() && !parentKillNotified && ShutdownSignal > 0 && parentPid > 1) {
291 debugs(1, DBG_IMPORTANT, "Killing master process, pid " << parentPid);
292 if (kill(parentPid, ShutdownSignal) < 0) {
293 int xerrno = errno;
294 debugs(1, DBG_IMPORTANT, "kill " << parentPid << ": " << xstrerr(xerrno));
295 }
296 parentKillNotified = true;
297 }
298#endif
299
300 if (shutting_down) {
301#if !KILL_PARENT_OPT
302 // Already a shutdown signal has received and shutdown is in progress.
303 // Shutdown as soon as possible.
304 wait = 0;
305#endif
306 } else {
307 shutting_down = 1;
308
309 /* run the closure code which can be shared with reconfigure */
311
313 }
314
315#if USE_WIN32_SERVICE
316 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000);
317#endif
318
319 eventAdd("SquidShutdown", &FinalShutdownRunners, this, (double) (wait + 1), 1, false);
320}
321
322void
324{
325 // no AvoidSignalAction() call: This code can run at any time because it
326 // does not depend on Squid state. It does not need debugging because it
327 // handles an "internal" signal, not an external/admin command.
329#if !_SQUID_WINDOWS_
330 PidStatus status;
331 pid_t pid;
332
333 do {
334 pid = WaitForAnyPid(status, WNOHANG);
335
336#if HAVE_SIGACTION
337
338 } while (pid > 0);
339
340#else
341
342 }
343 while (pid > 0 || (pid < 0 && errno == EINTR));
344#endif
345#endif
346}
347
348static void
349usage(void)
350{
351 fprintf(stderr,
352 "Usage: %s [-cdzCFNRVYX] [-n name] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]"
353#if USE_WIN32_SERVICE
354 "[-ir] [-O CommandLine]"
355#endif
356 "\n"
357 " -h | --help Print help message.\n"
358 " -v | --version Print version details.\n"
359 "\n"
360 " -a port Specify HTTP port number (default: %d).\n"
361 " -d level Write debugging to stderr also.\n"
362 " -f file Use given config-file instead of\n"
363 " %s\n"
364#if USE_WIN32_SERVICE
365 " -i Installs as a Windows Service (see -n option).\n"
366#endif
367 " -k reconfigure|rotate|shutdown|"
368#ifdef SIGTTIN
369 "restart|"
370#endif
371 "interrupt|kill|debug|check|parse\n"
372 " Parse configuration file, then send signal to \n"
373 " running copy (except -k parse) and exit.\n"
374 " -n name Specify service name to use for service operations\n"
375 " default is: " APP_SHORTNAME ".\n"
376#if USE_WIN32_SERVICE
377 " -r Removes a Windows Service (see -n option).\n"
378#endif
379 " -s | -l facility\n"
380 " Enable logging to syslog.\n"
381 " -u port Specify ICP port number (default: %d), disable with 0.\n"
382 " -z Create missing swap directories and then exit.\n"
383 " -C Do not catch fatal signals.\n"
384 " -D OBSOLETE. Scheduled for removal.\n"
385 " -F Don't serve any requests until store is rebuilt.\n"
386 " -N Master process runs in foreground and is a worker. No kids.\n"
387 " --foreground\n"
388 " Master process runs in foreground and creates worker kids.\n"
389 " --kid role-ID\n"
390 " Play a given SMP kid process role, with a given ID. Do not use\n"
391 " this option. It is meant for the master process use only.\n"
392#if USE_WIN32_SERVICE
393 " -O options\n"
394 " Set Windows Service Command line options in Registry.\n"
395#endif
396 " -R Do not set REUSEADDR on port.\n"
397 " -S Double-check swap during rebuild.\n"
398 " -X Force full debugging.\n"
399 " Add -d9 to also write full debugging to stderr.\n"
400 " -Y Only return UDP_HIT or UDP_MISS_NOFETCH during fast reload.\n",
401 APP_SHORTNAME, CACHE_HTTP_PORT, DEFAULT_CONFIG_FILE, CACHE_ICP_PORT);
402 exit(EXIT_FAILURE);
403}
404
406enum {
407 // The absolute values do not matter except that the following values should
408 // not be used: Values below 2 are for special getopt_long(3) use cases, and
409 // values in the [33,126] range are reserved for short options (-x).
411 optKid
413
414// short options
415// TODO: consider prefixing with ':' for better logging
416// (distinguish missing required argument cases)
417static const char *shortOpStr =
418#if USE_WIN32_SERVICE
419 "O:Vir"
420#endif
421 "CDFNRSYXa:d:f:hk:m::n:sl:u:vz?";
422
423// long options
424static struct option squidOptions[] = {
425 {"foreground", no_argument, nullptr, optForeground},
426 {"kid", required_argument, nullptr, optKid},
427 {"help", no_argument, nullptr, 'h'},
428 {"version", no_argument, nullptr, 'v'},
429 {nullptr, 0, nullptr, 0}
430};
431
432// handle a command line parameter
433static void
434mainHandleCommandLineOption(const int optId, const char *optValue)
435{
436 switch (optId) {
437
438 case 'C':
442 break;
443
444 case 'D':
447 debugs(1,DBG_CRITICAL, "WARNING: -D command-line option is obsolete.");
448 break;
449
450 case 'F':
454 break;
455
456 case 'N':
459 opt_no_daemon = 1;
460 break;
461
462#if USE_WIN32_SERVICE
463
464 case 'O':
468 WIN32_Command_Line = xstrdup(optValue);
469 break;
470#endif
471
472 case 'R':
475 opt_reuseaddr = 0;
476 break;
477
478 case 'S':
482 break;
483
484 case 'X':
487 Debug::parseOptions("rotate=0 ALL,9");
489 sigusr2_handle(SIGUSR2);
490 break;
491
492 case 'Y':
496 break;
497
498#if USE_WIN32_SERVICE
499
500 case 'i':
504 break;
505#endif
506
507 case 'a':
508 {
511 char *port = xstrdup(optValue);
512 // use a copy to avoid optValue modification
514 xfree(port);
515 break;
516 }
517
518 case 'd':
523 break;
524
525 case 'f':
529 ConfigFile = xstrdup(optValue);
530 break;
531
532 case 'k':
537 if (!optValue || strlen(optValue) < 1)
538 usage();
539
540 else if (!strncmp(optValue, "reconfigure", strlen(optValue)))
542 opt_send_signal = SIGHUP;
543 else if (!strncmp(optValue, "rotate", strlen(optValue)))
545#if defined(_SQUID_LINUX_THREADS_)
546 opt_send_signal = SIGQUIT;
547#else
548 opt_send_signal = SIGUSR1;
549#endif
550
551 else if (!strncmp(optValue, "debug", strlen(optValue)))
553#if defined(_SQUID_LINUX_THREADS_)
554 opt_send_signal = SIGTRAP;
555#else
556 opt_send_signal = SIGUSR2;
557#endif
558
559 else if (!strncmp(optValue, "shutdown", strlen(optValue)))
561 opt_send_signal = SIGTERM;
562 else if (!strncmp(optValue, "interrupt", strlen(optValue)))
564 opt_send_signal = SIGINT;
565 else if (!strncmp(optValue, "kill", strlen(optValue)))
566 // XXX: In SMP mode, uncatchable SIGKILL only kills the master process
568 opt_send_signal = SIGKILL;
569
570#ifdef SIGTTIN
571
572 else if (!strncmp(optValue, "restart", strlen(optValue)))
574 opt_send_signal = SIGTTIN;
575
576#endif
577
578 else if (!strncmp(optValue, "check", strlen(optValue)))
580 opt_send_signal = 0; /* SIGNULL */
581 else if (!strncmp(optValue, "parse", strlen(optValue)))
584 else
585 usage();
586
587 // Cannot use cache.log: use stderr for important messages (by default)
588 // and stop expecting a Debug::UseCacheLog() call.
591 break;
592
593 case 'm':
597 if (optValue) {
598#if MALLOC_DBG
599 malloc_debug_level = xatoi(optValue);
600#else
601 fatal("Need to add -DMALLOC_DBG when compiling to use -mX option");
602#endif
603
604 }
605 break;
606
607 case 'n':
611 if (optValue && *optValue != '\0') {
612 const SBuf t(optValue);
615 if (!tok.prefix(service_name, chr))
616 fatalf("Expected alphanumeric service name for the -n option but got: %s", optValue);
617 if (!tok.atEnd())
618 fatalf("Garbage after alphanumeric service name in the -n option value: %s", optValue);
619 if (service_name.length() > 32)
620 fatalf("Service name (-n option) must be limited to 32 characters but got %u", service_name.length());
621 opt_signal_service = true;
622 } else {
623 fatal("A service name is required for the -n option");
624 }
625 break;
626
627#if USE_WIN32_SERVICE
628
629 case 'r':
633
634 break;
635
636#endif
637
638 case 'l':
642 xfree(opt_syslog_facility); // ignore any previous options sent
643 opt_syslog_facility = xstrdup(optValue);
645 break;
646
647 case 's':
651 break;
652
653 case 'u':
657 icpPortNumOverride = atoi(optValue);
658
659 if (icpPortNumOverride < 0)
661
662 break;
663
664 case 'v':
667 printf("Squid Cache: Version %s\n",version_string);
668 printf("Service Name: " SQUIDSBUFPH "\n", SQUIDSBUFPRINT(service_name));
669 if (strlen(SQUID_BUILD_INFO))
670 printf("%s\n",SQUID_BUILD_INFO);
671#if USE_OPENSSL
672 printf("\nThis binary uses %s. ", OpenSSL_version(OPENSSL_VERSION));
673#if OPENSSL_VERSION_MAJOR < 3
674 printf("For legal restrictions on distribution see https://www.openssl.org/source/license.html\n\n");
675#endif
676#endif
677 printf( "configure options: %s\n", SQUID_CONFIGURE_OPTIONS);
678
679#if USE_WIN32_SERVICE
680
681 printf("Compiled as Windows System Service.\n");
682
683#endif
684
685 exit(EXIT_SUCCESS);
686
687 /* NOTREACHED */
688
689 case 'z':
693 // We will use cache.log, but this command is often executed on the
694 // command line, so use stderr to show important messages (by default).
695 // TODO: Generalize/fix this -z-specific and sometimes faulty logic with
696 // "use stderr when it is a tty [until we GoIntoBackground()]" logic.
698 break;
699
700 case optForeground:
703 opt_foreground = 1;
704 break;
705
706 case optKid:
707 // already processed in ConfigureCurrentKid()
708 break;
709
710 case 'h':
711
712 case '?':
713
714 default:
717 usage();
718
719 break;
720 }
721}
722
723/* ARGSUSED */
724void
726{
727 do_rotate = 1;
728 RotateSignal = sig;
729#if !_SQUID_WINDOWS_
730#if !HAVE_SIGACTION
731
732 signal(sig, rotate_logs);
733#endif
734#endif
735}
736
737/* ARGSUSED */
738void
740{
741 do_reconfigure = 1;
742 ReconfigureSignal = sig;
743#if !_SQUID_WINDOWS_
744#if !HAVE_SIGACTION
745
746 signal(sig, reconfigure);
747#endif
748#endif
749}
750
751static void
753{
754 ReviveKidsSignal = sig;
755 do_revive_kids = true;
756
757#if !_SQUID_WINDOWS_
758#if !HAVE_SIGACTION
759 signal(sig, master_revive_kids);
760#endif
761#endif
762}
763
765static void
767{
768 do_shutdown = 1;
769 ShutdownSignal = sig;
770
771#if !_SQUID_WINDOWS_
772#if !HAVE_SIGACTION
773 signal(sig, master_shutdown);
774#endif
775#endif
776
777}
778
779void
780shut_down(int sig)
781{
782 do_shutdown = sig == SIGINT ? -1 : 1;
783 ShutdownSignal = sig;
784#if defined(SIGTTIN)
785 if (SIGTTIN == sig)
786 shutdown_status = EXIT_FAILURE;
787#endif
788
789#if !defined(_SQUID_WINDOWS_) && !defined(HAVE_SIGACTION)
790 signal(sig, shut_down);
791#endif
792}
793
794void
795sig_child(int sig)
796{
798
799#if !defined(_SQUID_WINDOWS_) && !defined(HAVE_SIGACTION)
800 signal(sig, sig_child);
801#else
802 (void)sig;
803#endif
804}
805
806static void
808{
809 if (IamPrimaryProcess()) {
810#if USE_WCCP
812#endif
813
814#if USE_WCCPv2
815
817#endif
818 }
819 // start various proxying services if we are responsible for them
820 if (IamWorkerProcess()) {
822 icpOpenPorts();
823#if USE_HTCP
825#endif
826#if SQUID_SNMP
828#endif
829
831 netdbInit();
832 asnInit();
835
836 carpInit();
837#if USE_AUTH
839#endif
841 }
842}
843
844static void
846{
848
849 if (IamPrimaryProcess()) {
850#if USE_WCCP
851
853#endif
854#if USE_WCCPv2
855
857#endif
858 }
859 if (IamWorkerProcess()) {
862#if USE_HTCP
864#endif
865
867#if SQUID_SNMP
869#endif
870
872 }
873}
874
875static void
877{
878 if (AvoidSignalAction("reconfiguration", do_reconfigure))
879 return;
880
881 debugs(1, DBG_IMPORTANT, "Reconfiguring Squid Cache (version " << version_string << ")...");
882 reconfiguring = 1;
883
885
886 // Initiate asynchronous closing sequence
889#if USE_HTCP
891#endif
892#if USE_OPENSSL
894#endif
895#if USE_AUTH
897#endif
902#if ICAP_CLIENT
903 icapLogClose();
904#endif
906
907 eventAdd("mainReconfigureFinish", &mainReconfigureFinish, nullptr, 0, 1,
908 false);
909}
910
911static void
913{
914 debugs(1, 3, "finishing reconfiguring");
915
916 errorClean();
917 enter_suid(); /* root to read config file */
918
919 // we may have disabled the need for PURGE
922
923 // parse the config returns a count of errors encountered.
924 const int oldWorkers = Config.workers;
925 try {
926 if (parseConfigFile(ConfigFile) != 0) {
927 // for now any errors are a fatal condition...
929 }
930 } catch (...) {
931 // for now any errors are a fatal condition...
932 debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file. " <<
933 " Run squid -k parse and check for errors.");
935 }
936
937 if (oldWorkers != Config.workers) {
938 debugs(1, DBG_CRITICAL, "WARNING: Changing 'workers' (from " <<
939 oldWorkers << " to " << Config.workers <<
940 ") requires a full restart. It has been ignored by reconfigure.");
941 Config.workers = oldWorkers;
942 }
943
945
946 if (IamPrimaryProcess())
949
951 Mem::Report();
954 ipcache_restart(); /* clear stuck entries */
955 fqdncache_restart(); /* sigh, fqdncache too */
957 errorInitialize(); /* reload error pages */
959
960#if USE_LOADABLE_MODULES
962#endif
963
964#if USE_ADAPTATION
965 bool enableAdaptation = false;
966#if ICAP_CLIENT
968 enableAdaptation = Adaptation::Icap::TheConfig.onoff || enableAdaptation;
969#endif
970#if USE_ECAP
971 Adaptation::Ecap::TheConfig.finalize(); // must be after we load modules
972 enableAdaptation = Adaptation::Ecap::TheConfig.onoff || enableAdaptation;
973#endif
974 Adaptation::Config::Finalize(enableAdaptation);
975#endif
976
978#if ICAP_CLIENT
979 icapLogOpen();
980#endif
981 storeLogOpen();
982 Dns::Init();
983#if USE_SSL_CRTD
985#endif
986#if USE_OPENSSL
988#endif
989
991#if USE_AUTH
993#endif
995
996 if (IamPrimaryProcess()) {
997#if USE_WCCP
998
999 wccpInit();
1000#endif
1001#if USE_WCCPv2
1002
1003 wccp2Init();
1004#endif
1005 }
1006
1008
1010
1012
1014
1015 if (unlinkdNeeded())
1016 unlinkdInit();
1017
1018#if USE_DELAY_POOLS
1020#endif
1021
1022 reconfiguring = 0;
1023}
1024
1025static void
1027{
1028 if (AvoidSignalAction("log rotation", do_rotate))
1029 return;
1030
1031 icmpEngine.Close();
1033#if USE_AUTH
1035#endif
1037
1038 _db_rotate_log(); /* cache.log */
1040 storeLogRotate(); /* store.log */
1041 accessLogRotate(); /* access.log */
1043#if ICAP_CLIENT
1044 icapLogRotate(); /*icap.log*/
1045#endif
1046 icmpEngine.Open();
1047 redirectInit();
1048#if USE_AUTH
1050#endif
1052}
1053
1054static void
1056{
1058 leave_suid(); /* Run as non privilegied user */
1059#if _SQUID_OS2_
1060
1061 return;
1062#endif
1063
1064 if (geteuid() == 0) {
1065 debugs(0, DBG_CRITICAL, "Squid is not safe to run as root! If you must");
1066 debugs(0, DBG_CRITICAL, "start Squid as root, then you must configure");
1067 debugs(0, DBG_CRITICAL, "it to run as a non-priveledged user with the");
1068 debugs(0, DBG_CRITICAL, "'cache_effective_user' option in the config file.");
1069 fatal("Don't run Squid as root, set 'cache_effective_user'!");
1070 }
1071}
1072
1074static bool
1075mainChangeDir(const char *dir)
1076{
1077 if (chdir(dir) == 0)
1078 return true;
1079
1080 int xerrno = errno;
1081 debugs(50, DBG_CRITICAL, "ERROR: cannot change current directory to " << dir <<
1082 ": " << xstrerr(xerrno));
1083 return false;
1084}
1085
1088bool Chrooted = false;
1089
1091static void
1093{
1094 if (Config.chroot_dir && !Chrooted) {
1095 Chrooted = true;
1096
1097 if (chroot(Config.chroot_dir) != 0) {
1098 int xerrno = errno;
1099 fatalf("chroot to %s failed: %s", Config.chroot_dir, xstrerr(xerrno));
1100 }
1101
1102 if (!mainChangeDir("/"))
1103 fatalf("chdir to / after chroot to %s failed", Config.chroot_dir);
1104 }
1105
1106 if (Config.coredump_dir && strcmp("none", Config.coredump_dir) != 0) {
1108 debugs(0, Important(4), "Set Current Directory to " << Config.coredump_dir);
1109 return;
1110 }
1111 }
1112
1113 /* If we don't have coredump_dir or couldn't cd there, report current dir */
1114 char pathbuf[MAXPATHLEN];
1115 if (getcwd(pathbuf, MAXPATHLEN)) {
1116 debugs(0, DBG_IMPORTANT, "Current Directory is " << pathbuf);
1117 } else {
1118 int xerrno = errno;
1119 debugs(50, DBG_CRITICAL, "WARNING: Can't find current directory, getcwd: " << xstrerr(xerrno));
1120 }
1121}
1122
1123static void
1125{
1126 if (opt_catch_signals) {
1129 }
1130
1131 squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
1134
1136
1137 if (icpPortNumOverride != 1)
1138 Config.Port.icp = (unsigned short) icpPortNumOverride;
1139
1140 debugs(1, DBG_CRITICAL, "Starting Squid Cache version " << version_string << " for " << CONFIG_HOST_TYPE << "...");
1141 debugs(1, Critical(5), "Service Name: " << service_name);
1142
1143#if _SQUID_WINDOWS_
1144 if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
1145 debugs(1, DBG_CRITICAL, "Service command line is: " << WIN32_Service_Command_Line);
1146 } else
1147 debugs(1, DBG_CRITICAL, "Running on " << WIN32_OS_string);
1148#endif
1149
1150 debugs(1, Important(6), "Process ID " << getpid());
1151
1152 debugs(1, Important(7), "Process Roles:" << ProcessRoles());
1153
1155 debugs(1, Important(8), "With " << Squid_MaxFD << " file descriptors available");
1156
1157#if _SQUID_WINDOWS_
1158
1159 debugs(1, DBG_IMPORTANT, "With " << _getmaxstdio() << " CRT stdio descriptors available");
1160
1161 if (WIN32_Socks_initialized)
1162 debugs(1, DBG_IMPORTANT, "Windows sockets initialized");
1163
1164 if (WIN32_OS_version > _WIN_OS_WINNT) {
1166 }
1167
1168#endif
1169
1170 ipcache_init();
1171
1173
1174 parseEtcHosts();
1175
1176 Dns::Init();
1177
1178#if USE_SSL_CRTD
1180#endif
1181
1182#if USE_OPENSSL
1184#endif
1185
1186 redirectInit();
1187#if USE_AUTH
1189#endif
1191
1192 httpHeaderInitModule(); /* must go before any header processing (e.g. the one in errorInitialize) */
1193
1195
1196 accessLogInit();
1197
1199
1200#if ICAP_CLIENT
1201 icapLogOpen();
1202#endif
1203
1204#if SQUID_SNMP
1205
1206 snmpInit();
1207
1208#endif
1209#if MALLOC_DBG
1210
1211 malloc_debug(0, malloc_debug_level);
1212
1213#endif
1214
1215 if (unlinkdNeeded())
1216 unlinkdInit();
1217
1218 urlInitialize();
1219 statInit();
1220 storeInit();
1221 mainSetCwd();
1223 refreshInit();
1224#if USE_DELAY_POOLS
1226#endif
1227
1229 /* register the modules in the cache manager menus */
1230
1233
1234 /* These use separate calls so that the comm loops can eventually
1235 * coexist.
1236 */
1237
1238 eventInit();
1239
1240 // TODO: pconn is a good candidate for new-style registration
1241 // PconnModule::GetInstance()->registerWithCacheManager();
1242 // moved to PconnModule::PconnModule()
1243
1244 if (IamPrimaryProcess()) {
1245#if USE_WCCP
1246 wccpInit();
1247
1248#endif
1249#if USE_WCCPv2
1250
1251 wccp2Init();
1252
1253#endif
1254 }
1255
1257
1259
1260 // neighborsRegisterWithCacheManager(); //moved to neighbors_init()
1261
1262 if (Config.chroot_dir)
1263 no_suid();
1264
1265#if defined(_SQUID_LINUX_THREADS_)
1266
1268
1270
1271#else
1272
1274
1276
1277#endif
1278
1280
1282
1283#ifdef SIGTTIN
1284
1286
1287#endif
1288
1289 memCheckInit();
1290
1291#if USE_LOADABLE_MODULES
1293#endif
1294
1295#if USE_ADAPTATION
1296 bool enableAdaptation = false;
1297
1298 // We can remove this dependency on specific adaptation mechanisms
1299 // if we create a generic Registry of such mechanisms. Should we?
1300#if ICAP_CLIENT
1302 enableAdaptation = Adaptation::Icap::TheConfig.onoff || enableAdaptation;
1303#endif
1304#if USE_ECAP
1305 Adaptation::Ecap::TheConfig.finalize(); // must be after we load modules
1306 enableAdaptation = Adaptation::Ecap::TheConfig.onoff || enableAdaptation;
1307#endif
1308 // must be the last adaptation-related finalize
1309 Adaptation::Config::Finalize(enableAdaptation);
1310#endif
1311
1312#if USE_DELAY_POOLS
1314#endif
1315
1316 eventAdd("storeMaintain", Store::Maintain, nullptr, 1.0, 1);
1317
1318 eventAdd("ipcache_purgelru", ipcache_purgelru, nullptr, 10.0, 1);
1319
1320 eventAdd("fqdncache_purgelru", fqdncache_purgelru, nullptr, 15.0, 1);
1321
1322 eventAdd("memPoolCleanIdlePools", Mem::CleanIdlePools, nullptr, 15.0, 1);
1323
1324 configured_once = 1;
1325}
1326
1327static void
1329{
1330 // ignore recursive calls to avoid termination loops
1331 static bool terminating = false;
1332 if (terminating)
1333 return;
1334 terminating = true;
1335
1336 debugs(1, DBG_CRITICAL, "FATAL: Dying from an exception handling failure; exception: " << CurrentException);
1337
1339 abort();
1340}
1341
1343int SquidMain(int argc, char **argv);
1345static int SquidMainSafe(int argc, char **argv);
1346
1347#if USE_WIN32_SERVICE
1348/* Entry point for Windows services */
1349extern "C" void WINAPI
1350SquidWinSvcMain(int argc, char **argv)
1351{
1352 SquidMainSafe(argc, argv);
1353}
1354#endif
1355
1356int
1357main(int argc, char **argv)
1358{
1359#if USE_WIN32_SERVICE
1360 SetErrorMode(SEM_NOGPFAULTERRORBOX);
1361 if ((argc == 2) && strstr(argv[1], _WIN_SQUID_SERVICE_OPTION))
1362 return WIN32_StartService(argc, argv);
1363 else {
1364 WIN32_run_mode = _WIN_SQUID_RUN_MODE_INTERACTIVE;
1365 opt_no_daemon = 1;
1366 }
1367#endif
1368
1369 return SquidMainSafe(argc, argv);
1370}
1371
1372static int
1373SquidMainSafe(int argc, char **argv)
1374{
1375 (void)std::set_terminate(&OnTerminate);
1376 // XXX: This top-level catch works great for startup, but, during runtime,
1377 // it erases valuable stack info. TODO: Let stack-preserving OnTerminate()
1378 // handle FATAL runtime errors by splitting main code into protected
1379 // startup, unprotected runtime, and protected termination sections!
1380 try {
1381 return SquidMain(argc, argv);
1382 } catch (...) {
1383 debugs(1, DBG_CRITICAL, "FATAL: " << CurrentException);
1384 }
1385 return EXIT_FAILURE;
1386}
1387
1389static void
1391{
1392 const char *kidParams = nullptr;
1393 if (cmdLine.hasOption(optKid, &kidParams)) {
1394 SBuf processName(kidParams);
1395 SBuf kidId;
1396 Parser::Tokenizer tok(processName);
1397 tok.suffix(kidId, CharacterSet::DIGIT);
1398 KidIdentifier = xatoi(kidId.c_str());
1399 tok.skipSuffix(SBuf("-"));
1400 TheKidName = tok.remaining();
1401 if (TheKidName.cmp("squid-coord") == 0)
1403 else if (TheKidName.cmp("squid") == 0)
1405 else if (TheKidName.cmp("squid-disk") == 0)
1407 else
1408 TheProcessKind = pkOther; // including coordinator
1409 } else {
1411 KidIdentifier = 0;
1412 }
1414}
1415
1417static void
1419{
1420 if (opt_no_daemon) {
1421 fd_open(0, FD_LOG, "stdin");
1422 fd_open(1, FD_LOG, "stdout");
1423 fd_open(2, FD_LOG, "stderr");
1424 }
1425 // we should not create cache.log outside chroot environment, if any
1426 // XXX: With Config.chroot_dir set, SMP master process calls Debug::BanCacheLogUse().
1427 if (!Config.chroot_dir || Chrooted)
1429 else
1431}
1432
1433static void
1435{
1438}
1439
1440static void
1442{
1443 setMaxFD();
1444 fde::Init();
1445 const auto skipCwdAdjusting = IamMasterProcess() && InDaemonMode();
1446 if (skipCwdAdjusting) {
1449 } else if (Config.chroot_dir) {
1451 enter_suid();
1452 // TODO: don't we need to RunConfigUsers() in the configured
1453 // chroot environment?
1454 mainSetCwd();
1455 leave_suid();
1457 } else {
1460 enter_suid();
1461 // TODO: since RunConfigUsers() may use a relative path, we
1462 // need to change the process root first
1463 mainSetCwd();
1464 leave_suid();
1465 }
1466}
1467
1468int
1469SquidMain(int argc, char **argv)
1470{
1471 const CommandLine cmdLine(argc, argv, shortOpStr, squidOptions);
1472
1473 ConfigureCurrentKid(cmdLine);
1474
1475#if defined(SQUID_MAXFD_LIMIT)
1476
1479
1480#endif
1481
1482 /* NOP under non-windows */
1483 int WIN32_init_err=0;
1484 if ((WIN32_init_err = WIN32_Subsystem_Init(&argc, &argv)))
1485 return WIN32_init_err;
1486
1487 /* call mallopt() before anything else */
1488#if HAVE_MALLOPT
1489#ifdef M_GRAIN
1490 /* Round up all sizes to a multiple of this */
1491 mallopt(M_GRAIN, 16);
1492
1493#endif
1494#ifdef M_MXFAST
1495 /* biggest size that is considered a small block */
1496 mallopt(M_MXFAST, 256);
1497
1498#endif
1499#ifdef M_NBLKS
1500 /* allocate this many small blocks at once */
1501 mallopt(M_NLBLKS, 32);
1502
1503#endif
1504#endif /* HAVE_MALLOPT */
1505
1507
1509
1511
1512#if USE_WIN32_SERVICE
1513
1514 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1515
1516#endif
1517
1519
1522
1524 debugs(1, DBG_CRITICAL, "WARNING: --foreground command-line option has no effect with -N.");
1525 }
1526
1527#if USE_WIN32_SERVICE
1528
1529 if (opt_install_service) {
1531 return 0;
1532 }
1533
1534 if (opt_remove_service) {
1536 return 0;
1537 }
1538
1539 if (opt_command_line) {
1541 return 0;
1542 }
1543
1544#endif
1545
1546 /* parse configuration file
1547 * note: in "normal" case this used to be called from mainInitialize() */
1548 {
1549 int parse_err;
1550
1551 if (!ConfigFile)
1552 ConfigFile = xstrdup(DEFAULT_CONFIG_FILE);
1553
1555
1556 Mem::Init();
1557
1559
1560 storeFsInit(); /* required for config parsing */
1561
1562 Fs::Init();
1563
1564 /* May not be needed for parsing, have not audited for such */
1566
1567 /* we may want the parsing process to set this up in the future */
1568 Store::Init();
1569 Acl::Init();
1570 Auth::Init(); /* required for config parsing. NOP if !USE_AUTH */
1571 Ip::ProbeTransport(); // determine IPv4 or IPv6 capabilities before parsing.
1572
1573 Format::Token::Init(); // XXX: temporary. Use a runners registry of pre-parse runners instead.
1574
1576
1577 try {
1578 parse_err = parseConfigFile(ConfigFile);
1579 } catch (...) {
1580 // for now any errors are a fatal condition...
1581 debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file." <<
1582 (opt_parse_cfg_only ? " Run squid -k parse and check for errors." : ""));
1583 parse_err = 1;
1584 }
1585
1586 Mem::Report();
1587
1588 if (opt_parse_cfg_only || parse_err > 0)
1589 return parse_err;
1590 }
1592
1593 // Master optimization: Where possible, avoid pointless daemon fork() and/or
1594 // pointless wait for the exclusive PID file lock. This optional/weak check
1595 // is not applicable to kids because they always co-exist with their master.
1596 if (opt_send_signal == -1 && IamMasterProcess())
1598
1599 /* send signal to running copy and exit */
1600 if (opt_send_signal != -1) {
1601 /* chroot if configured to run inside chroot */
1602 mainSetCwd();
1603 if (Config.chroot_dir) {
1604 no_suid();
1605 } else {
1606 leave_suid();
1607 }
1608
1609 sendSignal();
1610 return 0;
1611 }
1612
1613 debugs(1,2, "Doing post-config initialization");
1614 leave_suid();
1616
1617 if (IamMasterProcess()) {
1618 if (InDaemonMode()) {
1619 watch_child(cmdLine);
1620 // NOTREACHED
1621 } else {
1623 }
1624 }
1625
1627 enter_suid();
1628
1631 debugs(0, DBG_CRITICAL, "Creating missing swap directories");
1632 Store::Root().create();
1633
1634 return 0;
1635 }
1636
1637 if (IamPrimaryProcess())
1640
1641 /* init comm module */
1642 comm_init();
1643
1644#if USE_WIN32_SERVICE
1645
1646 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1647
1648#endif
1649
1651
1652#if USE_WIN32_SERVICE
1653
1654 WIN32_svcstatusupdate(SERVICE_RUNNING, 0);
1655
1656#endif
1657
1658 /* main loop */
1659 EventLoop mainLoop;
1660
1661 SignalEngine signalEngine;
1662
1663 mainLoop.registerEngine(&signalEngine);
1664
1665 /* TODO: stop requiring the singleton here */
1667
1668 StoreRootEngine store_engine;
1669
1670 mainLoop.registerEngine(&store_engine);
1671
1672 CommSelectEngine comm_engine;
1673
1674 mainLoop.registerEngine(&comm_engine);
1675
1676 mainLoop.setPrimaryEngine(&comm_engine);
1677
1678 /* use the standard time service */
1679 Time::Engine time_engine;
1680
1681 mainLoop.setTimeService(&time_engine);
1682
1685 else if (UsingSmp() && (IamWorkerProcess() || IamDiskProcess()))
1687
1688 /* at this point we are finished the synchronous startup. */
1689 starting_up = 0;
1690
1691 mainLoop.run();
1692
1693 if (mainLoop.errcount == 10)
1694 fatal_dump("Event loop exited with failure.");
1695
1696 /* shutdown squid now */
1697 SquidShutdown();
1698
1699 /* NOTREACHED */
1700 return 0;
1701}
1702
1703static void
1705{
1706#if USE_WIN32_SERVICE
1707 // WIN32_sendSignal() does not need the PID value to signal,
1708 // but we must exit if there is no valid PID (TODO: Why?).
1709 (void)Instance::Other();
1710 if (!opt_signal_service)
1711 throw TexcHere("missing -n command line switch");
1713#else
1714 const auto pid = Instance::Other();
1715 if (kill(pid, opt_send_signal) &&
1716 /* ignore permissions if just running check */
1717 !(opt_send_signal == 0 && errno == EPERM)) {
1718 const auto savedErrno = errno;
1719 throw TexcHere(ToSBuf("failed to send signal ", opt_send_signal,
1720 " to Squid instance with PID ", pid, ": ", xstrerr(savedErrno)));
1721 }
1722#endif
1723 /* signal successfully sent */
1724}
1725
1726#if !_SQUID_WINDOWS_
1727/*
1728 * This function is run when Squid is in daemon mode, just
1729 * before the parent forks and starts up the child process.
1730 * It can be used for admin-specific tasks, such as notifying
1731 * someone that Squid is (re)started.
1732 */
1733static void
1734mainStartScript(const char *prog)
1735{
1736 char script[MAXPATHLEN];
1737 char *t;
1738 size_t sl = 0;
1739 pid_t cpid;
1740 pid_t rpid;
1741 xstrncpy(script, prog, MAXPATHLEN);
1742
1743 if ((t = strrchr(script, '/'))) {
1744 *(++t) = '\0';
1745 sl = strlen(script);
1746 }
1747
1748 xstrncpy(&script[sl], squid_start_script, MAXPATHLEN - sl);
1749
1750 if ((cpid = fork()) == 0) {
1751 /* child */
1752 execl(script, squid_start_script, (char *)nullptr);
1753 _exit(-1);
1754 } else {
1755 do {
1756 PidStatus status;
1757 rpid = WaitForOnePid(cpid, status, 0);
1758 } while (rpid != cpid);
1759 }
1760}
1761
1763static void
1765{
1766 if (AvoidSignalAction("shutdown", do_shutdown))
1767 return;
1768 debugs(1, 2, "received shutdown command");
1769 shutting_down = 1;
1770}
1771
1773static void
1775{
1776 if (AvoidSignalAction("reconfiguration", do_reconfigure))
1777 return;
1778 debugs(1, 2, "received reconfiguration command");
1779 reconfiguring = 1;
1781 // TODO: hot-reconfiguration of the number of kids, kids revival delay,
1782 // PID file location, etc.
1783}
1784
1786static void
1788{
1789 reconfiguring = 0;
1790}
1791
1793static void
1795{
1796 if (AvoidSignalAction("kids revival", do_revive_kids))
1797 return;
1798 debugs(1, 2, "woke up after ~" << Config.hopelessKidRevivalDelay << "s");
1799 // nothing to do here -- actual revival happens elsewhere in the main loop
1800 // the alarm was needed just to wake us up so that we do a loop iteration
1801}
1802
1803static void
1805{
1806 if (do_shutdown)
1808 if (do_reconfigure)
1810 if (do_revive_kids)
1812
1813 // emulate multi-step reconfiguration assumed by AvoidSignalAction()
1814 if (reconfiguring)
1816
1821 ReviveKidsSignal = -1; // alarms are not broadcasted
1822}
1823
1826static void
1828{
1829 const auto nextCheckDelay = TheKids.forgetOldFailures();
1830 assert(nextCheckDelay >= 0);
1831 (void)alarm(static_cast<unsigned int>(nextCheckDelay)); // resets or cancels
1832 if (nextCheckDelay)
1833 debugs(1, 2, "will recheck hopeless kids in " << nextCheckDelay << " seconds");
1834}
1835
1836static inline bool
1838{
1839 return (DebugSignal > 0 || RotateSignal > 0 || ReconfigureSignal > 0 ||
1840 ShutdownSignal > 0 || ReviveKidsSignal > 0);
1841}
1842
1844static void
1846{
1847 pid_t pid;
1848 if ((pid = fork()) < 0) {
1849 int xerrno = errno;
1850 throw TexcHere(ToSBuf("failed to fork(2) the master process: ", xstrerr(xerrno)));
1851 } else if (pid > 0) {
1852 // parent
1853 // The fork() effectively duped any saved debugs() messages. For
1854 // simplicity sake, let the child process deal with them.
1856 exit(EXIT_SUCCESS);
1857 }
1858 // child, running as a background daemon
1859 Must(setsid() > 0); // ought to succeed after fork()
1860}
1861
1862static void
1864{
1865 if (TheKids.someSignaled(SIGINT) || TheKids.someSignaled(SIGTERM)) {
1866 syslog(LOG_ALERT, "Exiting due to unexpected forced shutdown");
1867 exit(EXIT_FAILURE);
1868 }
1869
1870 if (TheKids.allHopeless()) {
1871 syslog(LOG_ALERT, "Exiting due to repeated, frequent failures");
1872 exit(EXIT_FAILURE);
1873 }
1874
1875 exit(EXIT_SUCCESS);
1876}
1877
1878#endif /* !_SQUID_WINDOWS_ */
1879
1880static void
1881watch_child(const CommandLine &masterCommand)
1882{
1883#if !_SQUID_WINDOWS_
1884 pid_t pid;
1885#ifdef TIOCNOTTY
1886
1887 int i;
1888#endif
1889
1890 int nullfd;
1891
1892 // TODO: zero values are not supported because they result in
1893 // misconfigured SMP Squid instances running forever, endlessly
1894 // restarting each dying kid.
1896 throw TexcHere("hopeless_kid_revival_delay must be positive");
1897
1898 enter_suid();
1899
1900 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1901
1902 if (!opt_foreground)
1904
1905 closelog();
1906
1907#ifdef TIOCNOTTY
1908
1909 if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
1910 ioctl(i, TIOCNOTTY, NULL);
1911 close(i);
1912 }
1913
1914#endif
1915
1916 /*
1917 * RBCOLLINS - if cygwin stackdumps when squid is run without
1918 * -N, check the cygwin1.dll version, it needs to be AT LEAST
1919 * 1.1.3. execvp had a bit overflow error in a loop..
1920 */
1921 /* Connect stdio to /dev/null in daemon mode */
1922 nullfd = open(_PATH_DEVNULL, O_RDWR | O_TEXT);
1923
1924 if (nullfd < 0) {
1925 int xerrno = errno;
1926 fatalf(_PATH_DEVNULL " %s\n", xstrerr(xerrno));
1927 }
1928
1929 dup2(nullfd, 0);
1930
1931 if (!Debug::StderrEnabled()) {
1932 dup2(nullfd, 1);
1933 dup2(nullfd, 2);
1934 }
1935
1936 leave_suid();
1939 enter_suid();
1940
1941#if defined(_SQUID_LINUX_THREADS_)
1942 squid_signal(SIGQUIT, rotate_logs, 0);
1943 squid_signal(SIGTRAP, sigusr2_handle, 0);
1944#else
1945 squid_signal(SIGUSR1, rotate_logs, 0);
1946 squid_signal(SIGUSR2, sigusr2_handle, 0);
1947#endif
1948
1949 squid_signal(SIGHUP, reconfigure, 0);
1950
1951 squid_signal(SIGTERM, master_shutdown, 0);
1952 squid_signal(SIGALRM, master_revive_kids, 0);
1953 squid_signal(SIGINT, master_shutdown, 0);
1954#ifdef SIGTTIN
1955 squid_signal(SIGTTIN, master_shutdown, 0);
1956#endif
1957
1958 if (Config.workers > 128) {
1959 syslog(LOG_ALERT, "Suspiciously high workers value: %d",
1960 Config.workers);
1961 // but we keep going in hope that user knows best
1962 }
1963 TheKids.init();
1964
1965 configured_once = 1;
1966
1967 syslog(LOG_NOTICE, "Squid Parent: will start %d kids", (int)TheKids.count());
1968
1969 // keep [re]starting kids until it is time to quit
1970 for (;;) {
1971 bool mainStartScriptCalled = false;
1972 // start each kid that needs to be [re]started; once
1973 for (int i = TheKids.count() - 1; i >= 0 && !shutting_down; --i) {
1974 Kid& kid = TheKids.get(i);
1975 if (!kid.shouldRestart())
1976 continue;
1977
1978 if (!mainStartScriptCalled) {
1979 mainStartScript(masterCommand.arg0());
1980 mainStartScriptCalled = true;
1981 }
1982
1983 // These are only needed by the forked child below, but let's keep
1984 // them out of that "no man's land" between fork() and execvp().
1985 auto kidCommand = masterCommand;
1986 kidCommand.resetArg0(kid.processName().c_str());
1987 assert(!kidCommand.hasOption(optKid));
1988 kidCommand.pushFrontOption("--kid", kid.gist().c_str());
1989
1990 if ((pid = fork()) == 0) {
1991 /* child */
1992 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1993 (void)execvp(masterCommand.arg0(), kidCommand.argv());
1994 int xerrno = errno;
1995 syslog(LOG_ALERT, "execvp failed: %s", xstrerr(xerrno));
1996 }
1997
1998 kid.start(pid);
1999 syslog(LOG_NOTICE, "Squid Parent: %s process %d started",
2000 kid.processName().c_str(), pid);
2001 }
2002
2003 /* parent */
2004 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
2005
2006 // If Squid received a signal while checking for dying kids (below) or
2007 // starting new kids (above), then do a fast check for a new dying kid
2008 // (WaitForAnyPid with the WNOHANG option) and continue to forward
2009 // signals to kids. Otherwise, wait for a kid to die or for a signal
2010 // to abort the blocking WaitForAnyPid() call.
2011 // With the WNOHANG option, we could check whether WaitForAnyPid() was
2012 // aborted by a dying kid or a signal, but it is not required: The
2013 // next do/while loop will check again for any dying kids.
2014 int waitFlag = 0;
2015 if (masterSignaled())
2016 waitFlag = WNOHANG;
2017 PidStatus status;
2018 pid = WaitForAnyPid(status, waitFlag);
2020
2021 // check for a stopped kid
2022 if (Kid *kid = pid > 0 ? TheKids.find(pid) : nullptr)
2023 kid->stop(status);
2024 else if (pid > 0)
2025 syslog(LOG_NOTICE, "Squid Parent: unknown child process %d exited", pid);
2026
2029
2031 leave_suid();
2032 // XXX: Master process has no main loop and, hence, should not call
2033 // RegisteredRunner::startShutdown which promises a loop iteration.
2035 enter_suid();
2036 masterExit();
2037 }
2038 }
2039
2040 /* NOTREACHED */
2041#endif /* _SQUID_WINDOWS_ */
2042
2043}
2044
2045static void
2047{
2048 /* XXX: This function is called after the main loop has quit, which
2049 * means that no AsyncCalls would be called, including close handlers.
2050 * TODO: We need to close/shut/free everything that needs calls before
2051 * exiting the loop.
2052 */
2053
2054#if USE_WIN32_SERVICE
2055 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2056#endif
2057
2058 debugs(1, Important(9), "Shutting down...");
2059#if USE_SSL_CRTD
2061#endif
2062#if USE_OPENSSL
2064#endif
2067 icpClosePorts();
2068#if USE_HTCP
2070#endif
2071#if SQUID_SNMP
2073#endif
2074#if USE_WCCP
2075
2077#endif
2078#if USE_WCCPv2
2079
2081#endif
2082
2085
2086#if USE_DELAY_POOLS
2088#endif
2089#if USE_AUTH
2091#endif
2092#if USE_WIN32_SERVICE
2093
2094 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2095#endif
2096#if ICAP_CLIENT
2098#endif
2099
2100 Store::Root().sync(); /* Flush pending object writes/unlinks */
2101
2102 unlinkdClose(); /* after sync/flush. NOP if !USE_UNLINKD */
2103
2105 PrintRusage();
2107 Store::Root().sync(); /* Flush log writes */
2108 storeLogClose();
2110 Store::Root().sync(); /* Flush log close */
2112
2113 fdDumpOpen();
2114
2115 comm_exit();
2116
2118
2119 memClean();
2120
2121 debugs(1, Important(10), "Squid Cache (Version " << version_string << "): Exiting normally.");
2122
2123 exit(shutdown_status);
2124}
2125
void accessLogInit(void)
Definition: access_log.cc:364
void accessLogClose(void)
Definition: access_log.cc:202
void accessLogRotate(void)
Definition: access_log.cc:182
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:673
int storeDirWriteCleanLogs(int reopen)
Definition: Disks.cc:696
void storeDirCloseSwapLogs()
Definition: Disks.cc:680
void httpHeaderInitModule(void)
Definition: HttpHeader.cc:119
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 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 & 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:59
#define Must(condition)
Definition: TextException.h:71
void urlInitialize(void)
Definition: Uri.cc:137
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:19
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:634
void add_http_port(char *portspec)
Definition: cache_cf.cc:3737
void self_destruct(void)
Definition: cache_cf.cc:276
void carpInit(void)
Definition: carp.cc:44
void cbdataRegisterWithCacheManager(void)
Definition: cbdata.cc:209
static void Initialize()
Definition: Acl.cc:412
virtual bool finalize()
Definition: Config.cc:184
static void Finalize(bool enable)
Definition: Config.cc:230
void freeService(void)
Definition: Config.cc:146
virtual bool finalize()
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:24
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
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:699
static bool StderrEnabled()
Definition: debug.cc:725
static void parseOptions(char const *)
Definition: debug.cc:1090
static void PrepareToDie()
Definition: debug.cc:561
static void ForgetSaved()
silently erases saved early debugs() messages (if any)
Definition: debug.cc:552
static void NameThisKid(int kidIdentifier)
Definition: debug.cc:405
static int override_X
Definition: Stream.h:88
static void SettleSyslog()
Definition: debug.cc:1140
static void UseCacheLog()
Definition: debug.cc:1120
static void BanCacheLogUse()
Definition: debug.cc:1113
static void ConfigureSyslog(const char *facility)
enables logging to syslog (using the specified facility, when not nil)
Definition: debug.cc:1078
static void EnsureDefaultStderrLevel(int maxDefault)
Definition: debug.cc:691
static void SettleStderr()
Definition: debug.cc:705
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:251
static void initModule()
Definition: FwdState.cc:1428
virtual void Close()
Shutdown pinger helper and control channel.
Definition: IcmpSquid.cc:254
virtual int Open()
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
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
virtual int checkEvents(int timeout)
Definition: main.cc:236
void doShutdown(time_t wait)
Definition: main.cc:281
static void FinalShutdownRunners(void *)
Definition: main.cc:214
void handleStoppedChild()
Definition: main.cc:323
static void StopEventLoop(void *)
Definition: main.cc:209
struct SquidConfig2::@126 onoff
char * mimeTablePathname
Definition: SquidConfig.h:224
wordlist * loadable_module_names
Definition: SquidConfig.h:530
ClientDelayConfig ClientDelay
Definition: SquidConfig.h:444
char * coredump_dir
Definition: SquidConfig.h:480
time_t shutdownLifetime
Definition: SquidConfig.h:105
char * chroot_dir
Definition: SquidConfig.h:481
unsigned short icp
Definition: SquidConfig.h:139
time_t hopelessKidRevivalDelay
hopeless_kid_revival_delay
Definition: SquidConfig.h:107
struct SquidConfig::@99 Port
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:249
void reconfigureStart()
When reconfigring should be called this method.
static void Init()
Init helper structure.
Definition: helper.cc:76
static void Reconfigure()
Definition: helper.cc:118
static void Shutdown()
Shutdown helper structure.
Definition: helper.cc:107
struct StatCounters::@128 client_http
int checkEvents(int)
Definition: main.cc:190
virtual void sync() override
prepare for shutdown
Definition: Controller.cc:218
virtual void create() override
create system resources needed for this store to operate in the future
Definition: Controller.cc:78
virtual 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
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:1164
void comm_exit(void)
Definition: comm.cc:1187
void commCloseAllSockets(void)
Definition: comm.cc:1468
void(* failure_notify)(const char *)
Definition: compat.cc:12
#define SA_RESTART
#define SA_RESETHAND
#define SQUID_MAXFD_LIMIT
Definition: compat_shared.h:84
#define SA_NODEFER
#define Critical(id)
Definition: Messages.h:90
#define Important(id)
Definition: Messages.h:91
#define DBG_IMPORTANT
Definition: Stream.h:41
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
#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:243
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:210
void asnInit(void)
Definition: Asn.cc:194
void errorInitialize(void)
Definition: errorpage.cc:253
void errorClean(void)
Definition: errorpage.cc:315
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:1093
void ipcache_init(void)
Definition: ipcache.cc:686
void ipcache_purgelru(void *)
Definition: ipcache.cc:350
void icpConnectionShutdown(void)
Definition: icp_v2.cc:779
void icpOpenPorts(void)
Definition: icp_v2.cc:696
void icpClosePorts(void)
Definition: icp_v2.cc:804
void htcpOpenPorts(void)
Definition: htcp.cc:1442
void htcpSocketShutdown(void)
Definition: htcp.cc:1617
void htcpClosePorts(void)
Definition: htcp.cc:1646
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:1055
static void master_shutdown(int sig)
Shutdown signal handler for master process.
Definition: main.cc:766
static void StartUsingConfig()
Definition: main.cc:1441
static void watch_child(const CommandLine &)
Definition: main.cc:1881
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:876
static void ConfigureDebugging()
Start directing debugs() messages to the configured cache.log.
Definition: main.cc:1418
static int opt_signal_service
Definition: main.cc:143
int SquidMain(int argc, char **argv)
unsafe main routine – may throw
Definition: main.cc:1469
static void masterReviveKids()
Reacts to the kid revival alarm.
Definition: main.cc:1794
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 GoIntoBackground()
makes the caller a daemon process running in the background
Definition: main.cc:1845
int main(int argc, char **argv)
Definition: main.cc:1357
static struct option squidOptions[]
Definition: main.cc:424
static volatile int do_revive_kids
Definition: main.cc:153
static void mainSetCwd(void)
set the working directory.
Definition: main.cc:1092
static void ConfigureCurrentKid(const CommandLine &cmdLine)
computes name and ID for the current kid process
Definition: main.cc:1390
static volatile int do_shutdown
Definition: main.cc:152
void rotate_logs(int sig)
Definition: main.cc:725
static void RunConfigUsers()
Definition: main.cc:1434
void sig_child(int sig)
Definition: main.cc:795
static int configured_once
Definition: main.cc:146
static void mainHandleCommandLineOption(const int optId, const char *optValue)
Definition: main.cc:434
static int opt_remove_service
Definition: main.cc:137
static void master_revive_kids(int sig)
Definition: main.cc:752
static void SquidShutdown(void)
Definition: main.cc:2046
void WINAPI SquidWinSvcMain(int argc, char **argv)
Definition: main.cc:1350
static void masterShutdownStart()
Initiates shutdown sequence. Shutdown ends when the last running kids stops.
Definition: main.cc:1764
static bool mainChangeDir(const char *dir)
changes working directory, providing error reporting
Definition: main.cc:1075
static void masterExit()
Definition: main.cc:1863
static void OnTerminate()
Definition: main.cc:1328
static int RotateSignal
Definition: main.cc:157
static int SquidMainSafe(int argc, char **argv)
unsafe main routine wrapper to catch exceptions
Definition: main.cc:1373
static int ReconfigureSignal
Definition: main.cc:158
static int ShutdownSignal
Definition: main.cc:159
static void mainReconfigureFinish(void *)
Definition: main.cc:912
void WIN32_svcstatusupdate(DWORD, DWORD)
Definition: WinSvc.cc:567
static void sendSignal(void)
Definition: main.cc:1704
static const char * squid_start_script
Definition: main.cc:177
static int icpPortNumOverride
Definition: main.cc:145
static void serverConnectionsOpen(void)
Definition: main.cc:807
static const char * shortOpStr
Definition: main.cc:417
static void masterCheckAndBroadcastSignals()
Definition: main.cc:1804
static volatile int shutdown_status
Definition: main.cc:154
static void masterMaintainKidRevivalSchedule()
Definition: main.cc:1827
@ optKid
Definition: main.cc:411
@ optForeground
Definition: main.cc:410
bool Chrooted
Definition: main.cc:1088
static void mainStartScript(const char *prog)
Definition: main.cc:1734
static int opt_install_service
Definition: main.cc:136
void reconfigure(int sig)
Definition: main.cc:739
static void masterReconfigureFinish()
Ends reconfiguration sequence started by masterReconfigureStart().
Definition: main.cc:1787
static void mainRotate(void)
Definition: main.cc:1026
static void usage(void)
Definition: main.cc:349
static void masterReconfigureStart()
Initiates reconfiguration sequence. See also: masterReconfigureFinish().
Definition: main.cc:1774
static bool AvoidSignalAction(const char *description, volatile int &signalVar)
Definition: main.cc:252
static volatile int do_rotate
Definition: main.cc:151
static void serverConnectionsClose(void)
Definition: main.cc:845
static bool masterSignaled()
Definition: main.cc:1837
void shut_down(int sig)
Definition: main.cc:780
static void mainInitialize(void)
Definition: main.cc:1124
static char * opt_syslog_facility
Definition: main.cc:144
void memClean(void)
Main cleanup handler.
Definition: old_api.cc:494
void memCheckInit(void)
Definition: stub_libmem.cc:84
void mimeInit(char *filename)
Definition: mime.cc:231
void Init(void)
prepares to parse ACLs configuration
Definition: AclRegs.cc:114
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
void Init(void)
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 Report()
Definition: old_api.cc:460
void CleanIdlePools(void *unused)
Definition: old_api.cc:399
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:926
void Maintain(void *unused)
Definition: store.cc:1105
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:933
#define xfree
#define xstrdup
void neighbors_init(void)
Definition: neighbors.cc:554
void netdbInit(void)
Definition: net_db.cc:866
#define OPENSSL_VERSION
Definition: openssl.h:133
#define OpenSSL_version
Definition: openssl.h:134
void peerSelectInit(void)
Definition: peer_select.cc:918
void peerSourceHashInit(void)
void peerUserHashInit(void)
void redirectInit(void)
Definition: redirect.cc:333
void redirectReconfigure()
Definition: redirect.cc:435
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:68
void snmpOpenPorts(void)
Definition: snmp_core.cc:256
void snmpClosePorts(void)
Definition: snmp_core.cc:319
#define CACHE_ICP_PORT
Definition: squid.h:17
#define CACHE_HTTP_PORT
Definition: squid.h:16
void _db_rotate_log(void)
Definition: debug.cc:1155
void statInit(void)
Definition: stat.cc:1247
#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:1230
void storeFsInit(void)
Definition: store.cc:1603
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:556
bool IamMasterProcess()
whether the current process is the parent of all other Squid processes
Definition: tools.cc:665
bool InDaemonMode()
Whether we are running in daemon mode.
Definition: tools.cc:687
void squid_signal(int sig, SIGHDLR *func, int flags)
Definition: tools.cc:870
pid_t WaitForOnePid(pid_t pid, PidStatus &status, int flags)
Definition: tools.cc:1177
void setUmask(mode_t mask)
Definition: tools.cc:1066
void death(int sig)
Definition: tools.cc:342
void sigusr2_handle(int sig)
Definition: tools.cc:430
void setMaxFD(void)
Definition: tools.cc:759
bool IamPrimaryProcess()
Definition: tools.cc:705
void no_suid(void)
Definition: tools.cc:643
void PrintRusage(void)
Definition: tools.cc:326
void enter_suid(void)
Definition: tools.cc:620
void BroadcastSignalIfAny(int &sig)
Definition: tools.cc:415
bool IamCoordinatorProcess()
whether the current process coordinates worker processes
Definition: tools.cc:699
void dumpMallocStats(void)
Definition: tools.cc:163
bool UsingSmp()
Whether there should be more than one worker process running.
Definition: tools.cc:693
SBuf ProcessRoles()
a string describing this process roles such as worker or coordinator
Definition: tools.cc:736
void setSystemLimits(void)
Definition: tools.cc:808
int PidStatus
Definition: tools.h:91
pid_t WaitForAnyPid(PidStatus &status, int flags)
Definition: tools.h:107
#define NULL
Definition: types.h:166
bool unlinkdNeeded(void)
Definition: unlinkd.cc:178
void unlinkdClose(void)
Definition: unlinkd.cc:131
void unlinkdInit(void)
Definition: unlinkd.cc:191
#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