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
1206 /* These use separate calls so that the comm loops can eventually
1207 * coexist.
1208 */
1209
1210 eventInit();
1211
1212 // TODO: pconn is a good candidate for new-style registration
1213 // PconnModule::GetInstance()->registerWithCacheManager();
1214 // moved to PconnModule::PconnModule()
1215
1216 if (IamPrimaryProcess()) {
1217#if USE_WCCP
1218 wccpInit();
1219
1220#endif
1221#if USE_WCCPv2
1222
1223 wccp2Init();
1224
1225#endif
1226 }
1227
1229
1231
1232 // neighborsRegisterWithCacheManager(); //moved to neighbors_init()
1233
1234 if (Config.chroot_dir)
1235 no_suid();
1236
1237#if defined(_SQUID_LINUX_THREADS_)
1238
1240
1242
1243#else
1244
1246
1248
1249#endif
1250
1252
1254
1255#ifdef SIGTTIN
1256
1258
1259#endif
1260
1261 memCheckInit();
1262
1263#if USE_LOADABLE_MODULES
1265#endif
1266
1267#if USE_ADAPTATION
1268 bool enableAdaptation = false;
1269
1270 // We can remove this dependency on specific adaptation mechanisms
1271 // if we create a generic Registry of such mechanisms. Should we?
1272#if ICAP_CLIENT
1274 enableAdaptation = Adaptation::Icap::TheConfig.onoff || enableAdaptation;
1275#endif
1276#if USE_ECAP
1277 Adaptation::Ecap::TheConfig.finalize(); // must be after we load modules
1278 enableAdaptation = Adaptation::Ecap::TheConfig.onoff || enableAdaptation;
1279#endif
1280 // must be the last adaptation-related finalize
1281 Adaptation::Config::Finalize(enableAdaptation);
1282#endif
1283
1284#if USE_DELAY_POOLS
1286#endif
1287
1288 eventAdd("storeMaintain", Store::Maintain, nullptr, 1.0, 1);
1289
1290 eventAdd("ipcache_purgelru", ipcache_purgelru, nullptr, 10.0, 1);
1291
1292 eventAdd("fqdncache_purgelru", fqdncache_purgelru, nullptr, 15.0, 1);
1293
1294 eventAdd("memPoolCleanIdlePools", Mem::CleanIdlePools, nullptr, 15.0, 1);
1295
1296 configured_once = 1;
1297}
1298
1299static void
1301{
1302 // ignore recursive calls to avoid termination loops
1303 static bool terminating = false;
1304 if (terminating)
1305 return;
1306 terminating = true;
1307
1308 debugs(1, DBG_CRITICAL, "FATAL: Dying from an exception handling failure; exception: " << CurrentException);
1309
1311 abort();
1312}
1313
1315int SquidMain(int argc, char **argv);
1317static int SquidMainSafe(int argc, char **argv);
1318
1319#if USE_WIN32_SERVICE
1320/* Entry point for Windows services */
1321extern "C" void WINAPI
1322SquidWinSvcMain(int argc, char **argv)
1323{
1324 SquidMainSafe(argc, argv);
1325}
1326#endif
1327
1328int
1329main(int argc, char **argv)
1330{
1331#if USE_WIN32_SERVICE
1332 SetErrorMode(SEM_NOGPFAULTERRORBOX);
1333 if ((argc == 2) && strstr(argv[1], _WIN_SQUID_SERVICE_OPTION))
1334 return WIN32_StartService(argc, argv);
1335 else {
1336 WIN32_run_mode = _WIN_SQUID_RUN_MODE_INTERACTIVE;
1337 opt_no_daemon = 1;
1338 }
1339#endif
1340
1341 return SquidMainSafe(argc, argv);
1342}
1343
1344static int
1345SquidMainSafe(int argc, char **argv)
1346{
1347 (void)std::set_terminate(&OnTerminate);
1348 // XXX: This top-level catch works great for startup, but, during runtime,
1349 // it erases valuable stack info. TODO: Let stack-preserving OnTerminate()
1350 // handle FATAL runtime errors by splitting main code into protected
1351 // startup, unprotected runtime, and protected termination sections!
1352 try {
1353 return SquidMain(argc, argv);
1354 } catch (...) {
1355 debugs(1, DBG_CRITICAL, "FATAL: " << CurrentException);
1356 }
1357 return EXIT_FAILURE;
1358}
1359
1361static void
1363{
1364 const char *kidParams = nullptr;
1365 if (cmdLine.hasOption(optKid, &kidParams)) {
1366 SBuf processName(kidParams);
1367 SBuf kidId;
1368 Parser::Tokenizer tok(processName);
1369 tok.suffix(kidId, CharacterSet::DIGIT);
1370 KidIdentifier = xatoi(kidId.c_str());
1371 tok.skipSuffix(SBuf("-"));
1372 TheKidName = tok.remaining();
1373 if (TheKidName.cmp("squid-coord") == 0)
1375 else if (TheKidName.cmp("squid") == 0)
1377 else if (TheKidName.cmp("squid-disk") == 0)
1379 else
1380 TheProcessKind = pkOther; // including coordinator
1381 } else {
1383 KidIdentifier = 0;
1384 }
1386}
1387
1389static void
1391{
1392 if (opt_no_daemon) {
1393 fd_open(0, FD_LOG, "stdin");
1394 fd_open(1, FD_LOG, "stdout");
1395 fd_open(2, FD_LOG, "stderr");
1396 }
1397 // we should not create cache.log outside chroot environment, if any
1398 // XXX: With Config.chroot_dir set, SMP master process calls Debug::BanCacheLogUse().
1399 if (!Config.chroot_dir || Chrooted)
1401 else
1403}
1404
1405static void
1407{
1410}
1411
1412static void
1414{
1415 setMaxFD();
1416 fde::Init();
1417 const auto skipCwdAdjusting = IamMasterProcess() && InDaemonMode();
1418 if (skipCwdAdjusting) {
1421 } else if (Config.chroot_dir) {
1423 enter_suid();
1424 // TODO: don't we need to RunConfigUsers() in the configured
1425 // chroot environment?
1426 mainSetCwd();
1427 leave_suid();
1429 } else {
1432 enter_suid();
1433 // TODO: since RunConfigUsers() may use a relative path, we
1434 // need to change the process root first
1435 mainSetCwd();
1436 leave_suid();
1437 }
1438}
1439
1440int
1441SquidMain(int argc, char **argv)
1442{
1443 const CommandLine cmdLine(argc, argv, shortOpStr, squidOptions);
1444
1445 ConfigureCurrentKid(cmdLine);
1446
1447#if defined(SQUID_MAXFD_LIMIT)
1448
1451
1452#endif
1453
1454 /* NOP under non-windows */
1455 int WIN32_init_err=0;
1456 if ((WIN32_init_err = WIN32_Subsystem_Init(&argc, &argv)))
1457 return WIN32_init_err;
1458
1459 /* call mallopt() before anything else */
1460#if HAVE_MALLOPT
1461#ifdef M_GRAIN
1462 /* Round up all sizes to a multiple of this */
1463 mallopt(M_GRAIN, 16);
1464
1465#endif
1466#ifdef M_MXFAST
1467 /* biggest size that is considered a small block */
1468 mallopt(M_MXFAST, 256);
1469
1470#endif
1471#ifdef M_NBLKS
1472 /* allocate this many small blocks at once */
1473 mallopt(M_NLBLKS, 32);
1474
1475#endif
1476#endif /* HAVE_MALLOPT */
1477
1479
1481
1483
1484#if USE_WIN32_SERVICE
1485
1486 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1487
1488#endif
1489
1491
1494
1496 debugs(1, DBG_CRITICAL, "WARNING: --foreground command-line option has no effect with -N.");
1497 }
1498
1499#if USE_WIN32_SERVICE
1500
1501 if (opt_install_service) {
1503 return 0;
1504 }
1505
1506 if (opt_remove_service) {
1508 return 0;
1509 }
1510
1511 if (opt_command_line) {
1513 return 0;
1514 }
1515
1516#endif
1517
1518 /* parse configuration file
1519 * note: in "normal" case this used to be called from mainInitialize() */
1520 {
1521 int parse_err;
1522
1523 if (!ConfigFile)
1524 ConfigFile = xstrdup(DEFAULT_CONFIG_FILE);
1525
1527
1528 Mem::Init();
1529
1531
1532 storeFsInit(); /* required for config parsing */
1533
1534 Fs::Init();
1535
1536 /* May not be needed for parsing, have not audited for such */
1538
1539 /* we may want the parsing process to set this up in the future */
1540 Store::Init();
1541 Acl::Init();
1542 Auth::Init(); /* required for config parsing. NOP if !USE_AUTH */
1543 Ip::ProbeTransport(); // determine IPv4 or IPv6 capabilities before parsing.
1544
1545 Format::Token::Init(); // XXX: temporary. Use a runners registry of pre-parse runners instead.
1546
1548
1549 try {
1550 parse_err = parseConfigFile(ConfigFile);
1551 } catch (...) {
1552 // for now any errors are a fatal condition...
1553 debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file." <<
1554 (opt_parse_cfg_only ? " Run squid -k parse and check for errors." : ""));
1555 parse_err = 1;
1556 }
1557
1558 if (opt_parse_cfg_only || parse_err > 0)
1559 return parse_err;
1560 }
1562
1563 // Master optimization: Where possible, avoid pointless daemon fork() and/or
1564 // pointless wait for the exclusive PID file lock. This optional/weak check
1565 // is not applicable to kids because they always co-exist with their master.
1566 if (opt_send_signal == -1 && IamMasterProcess())
1568
1569 /* send signal to running copy and exit */
1570 if (opt_send_signal != -1) {
1571 /* chroot if configured to run inside chroot */
1572 mainSetCwd();
1573 if (Config.chroot_dir) {
1574 no_suid();
1575 } else {
1576 leave_suid();
1577 }
1578
1579 sendSignal();
1580 return 0;
1581 }
1582
1583 debugs(1,2, "Doing post-config initialization");
1584 leave_suid();
1586
1587 if (IamMasterProcess()) {
1588 if (InDaemonMode()) {
1589 watch_child(cmdLine);
1590 // NOTREACHED
1591 } else {
1593 }
1594 }
1595
1597 enter_suid();
1598
1601 debugs(0, DBG_CRITICAL, "Creating missing swap directories");
1602 Store::Root().create();
1603
1604 return 0;
1605 }
1606
1607 if (IamPrimaryProcess())
1610
1611 /* init comm module */
1612 comm_init();
1613
1614#if USE_WIN32_SERVICE
1615
1616 WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000);
1617
1618#endif
1619
1621
1622#if USE_WIN32_SERVICE
1623
1624 WIN32_svcstatusupdate(SERVICE_RUNNING, 0);
1625
1626#endif
1627
1628 /* main loop */
1629 EventLoop mainLoop;
1630
1631 SignalEngine signalEngine;
1632
1633 mainLoop.registerEngine(&signalEngine);
1634
1635 /* TODO: stop requiring the singleton here */
1637
1638 StoreRootEngine store_engine;
1639
1640 mainLoop.registerEngine(&store_engine);
1641
1642 CommSelectEngine comm_engine;
1643
1644 mainLoop.registerEngine(&comm_engine);
1645
1646 mainLoop.setPrimaryEngine(&comm_engine);
1647
1648 /* use the standard time service */
1649 Time::Engine time_engine;
1650
1651 mainLoop.setTimeService(&time_engine);
1652
1655 else if (UsingSmp() && (IamWorkerProcess() || IamDiskProcess()))
1657
1658 /* at this point we are finished the synchronous startup. */
1659 starting_up = 0;
1660
1661 mainLoop.run();
1662
1663 if (mainLoop.errcount == 10)
1664 fatal_dump("Event loop exited with failure.");
1665
1666 /* shutdown squid now */
1667 SquidShutdown();
1668
1669 /* NOTREACHED */
1670 return 0;
1671}
1672
1673static void
1675{
1676#if USE_WIN32_SERVICE
1677 // WIN32_sendSignal() does not need the PID value to signal,
1678 // but we must exit if there is no valid PID (TODO: Why?).
1679 (void)Instance::Other();
1680 if (!opt_signal_service)
1681 throw TexcHere("missing -n command line switch");
1683#else
1684 const auto pid = Instance::Other();
1685 if (kill(pid, opt_send_signal) &&
1686 /* ignore permissions if just running check */
1687 !(opt_send_signal == 0 && errno == EPERM)) {
1688 const auto savedErrno = errno;
1689 throw TexcHere(ToSBuf("failed to send signal ", opt_send_signal,
1690 " to Squid instance with PID ", pid, ": ", xstrerr(savedErrno)));
1691 }
1692#endif
1693 /* signal successfully sent */
1694}
1695
1696#if !_SQUID_WINDOWS_
1697/*
1698 * This function is run when Squid is in daemon mode, just
1699 * before the parent forks and starts up the child process.
1700 * It can be used for admin-specific tasks, such as notifying
1701 * someone that Squid is (re)started.
1702 */
1703static void
1704mainStartScript(const char *prog)
1705{
1706 char script[MAXPATHLEN];
1707 char *t;
1708 size_t sl = 0;
1709 pid_t cpid;
1710 pid_t rpid;
1711 xstrncpy(script, prog, MAXPATHLEN);
1712
1713 if ((t = strrchr(script, '/'))) {
1714 *(++t) = '\0';
1715 sl = strlen(script);
1716 }
1717
1718 xstrncpy(&script[sl], squid_start_script, MAXPATHLEN - sl);
1719
1720 if ((cpid = fork()) == 0) {
1721 /* child */
1722 execl(script, squid_start_script, (char *)nullptr);
1723 _exit(-1);
1724 } else {
1725 do {
1726 PidStatus status;
1727 rpid = WaitForOnePid(cpid, status, 0);
1728 } while (rpid != cpid);
1729 }
1730}
1731
1733static void
1735{
1736 if (AvoidSignalAction("shutdown", do_shutdown))
1737 return;
1738 debugs(1, 2, "received shutdown command");
1739 shutting_down = 1;
1740}
1741
1743static void
1745{
1746 if (AvoidSignalAction("reconfiguration", do_reconfigure))
1747 return;
1748 debugs(1, 2, "received reconfiguration command");
1749 reconfiguring = 1;
1751 // TODO: hot-reconfiguration of the number of kids, kids revival delay,
1752 // PID file location, etc.
1753}
1754
1756static void
1758{
1759 reconfiguring = 0;
1760}
1761
1763static void
1765{
1766 if (AvoidSignalAction("kids revival", do_revive_kids))
1767 return;
1768 debugs(1, 2, "woke up after ~" << Config.hopelessKidRevivalDelay << "s");
1769 // nothing to do here -- actual revival happens elsewhere in the main loop
1770 // the alarm was needed just to wake us up so that we do a loop iteration
1771}
1772
1773static void
1775{
1776 if (do_shutdown)
1778 if (do_reconfigure)
1780 if (do_revive_kids)
1782
1783 // emulate multi-step reconfiguration assumed by AvoidSignalAction()
1784 if (reconfiguring)
1786
1791 ReviveKidsSignal = -1; // alarms are not broadcasted
1792}
1793
1796static void
1798{
1799 const auto nextCheckDelay = TheKids.forgetOldFailures();
1800 assert(nextCheckDelay >= 0);
1801 (void)alarm(static_cast<unsigned int>(nextCheckDelay)); // resets or cancels
1802 if (nextCheckDelay)
1803 debugs(1, 2, "will recheck hopeless kids in " << nextCheckDelay << " seconds");
1804}
1805
1806static inline bool
1808{
1809 return (DebugSignal > 0 || RotateSignal > 0 || ReconfigureSignal > 0 ||
1810 ShutdownSignal > 0 || ReviveKidsSignal > 0);
1811}
1812
1814static void
1816{
1817 pid_t pid;
1818 if ((pid = fork()) < 0) {
1819 int xerrno = errno;
1820 throw TexcHere(ToSBuf("failed to fork(2) the master process: ", xstrerr(xerrno)));
1821 } else if (pid > 0) {
1822 // parent
1823 // The fork() effectively duped any saved debugs() messages. For
1824 // simplicity sake, let the child process deal with them.
1826 exit(EXIT_SUCCESS);
1827 }
1828 // child, running as a background daemon
1829 Must(setsid() > 0); // ought to succeed after fork()
1830}
1831
1832static void
1834{
1835 if (TheKids.someSignaled(SIGINT) || TheKids.someSignaled(SIGTERM)) {
1836 syslog(LOG_ALERT, "Exiting due to unexpected forced shutdown");
1837 exit(EXIT_FAILURE);
1838 }
1839
1840 if (TheKids.allHopeless()) {
1841 syslog(LOG_ALERT, "Exiting due to repeated, frequent failures");
1842 exit(EXIT_FAILURE);
1843 }
1844
1845 exit(EXIT_SUCCESS);
1846}
1847
1848#endif /* !_SQUID_WINDOWS_ */
1849
1850static void
1851watch_child(const CommandLine &masterCommand)
1852{
1853#if !_SQUID_WINDOWS_
1854 pid_t pid;
1855#ifdef TIOCNOTTY
1856
1857 int i;
1858#endif
1859
1860 int nullfd;
1861
1862 // TODO: zero values are not supported because they result in
1863 // misconfigured SMP Squid instances running forever, endlessly
1864 // restarting each dying kid.
1866 throw TexcHere("hopeless_kid_revival_delay must be positive");
1867
1868 enter_suid();
1869
1870 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1871
1872 if (!opt_foreground)
1874
1875 closelog();
1876
1877#ifdef TIOCNOTTY
1878
1879 if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
1880 ioctl(i, TIOCNOTTY, NULL);
1881 close(i);
1882 }
1883
1884#endif
1885
1886 /*
1887 * RBCOLLINS - if cygwin stackdumps when squid is run without
1888 * -N, check the cygwin1.dll version, it needs to be AT LEAST
1889 * 1.1.3. execvp had a bit overflow error in a loop..
1890 */
1891 /* Connect stdio to /dev/null in daemon mode */
1892 nullfd = open(_PATH_DEVNULL, O_RDWR | O_TEXT);
1893
1894 if (nullfd < 0) {
1895 int xerrno = errno;
1896 fatalf(_PATH_DEVNULL " %s\n", xstrerr(xerrno));
1897 }
1898
1899 dup2(nullfd, 0);
1900
1901 if (!Debug::StderrEnabled()) {
1902 dup2(nullfd, 1);
1903 dup2(nullfd, 2);
1904 }
1905
1906 leave_suid();
1909 enter_suid();
1910
1911#if defined(_SQUID_LINUX_THREADS_)
1912 squid_signal(SIGQUIT, rotate_logs, 0);
1913 squid_signal(SIGTRAP, sigusr2_handle, 0);
1914#else
1915 squid_signal(SIGUSR1, rotate_logs, 0);
1916 squid_signal(SIGUSR2, sigusr2_handle, 0);
1917#endif
1918
1919 squid_signal(SIGHUP, reconfigure, 0);
1920
1921 squid_signal(SIGTERM, master_shutdown, 0);
1922 squid_signal(SIGALRM, master_revive_kids, 0);
1923 squid_signal(SIGINT, master_shutdown, 0);
1924#ifdef SIGTTIN
1925 squid_signal(SIGTTIN, master_shutdown, 0);
1926#endif
1927
1928 if (Config.workers > 128) {
1929 syslog(LOG_ALERT, "Suspiciously high workers value: %d",
1930 Config.workers);
1931 // but we keep going in hope that user knows best
1932 }
1933 TheKids.init();
1934
1935 configured_once = 1;
1936
1937 syslog(LOG_NOTICE, "Squid Parent: will start %d kids", (int)TheKids.count());
1938
1939 // keep [re]starting kids until it is time to quit
1940 for (;;) {
1941 bool mainStartScriptCalled = false;
1942 // start each kid that needs to be [re]started; once
1943 for (int i = TheKids.count() - 1; i >= 0 && !shutting_down; --i) {
1944 Kid& kid = TheKids.get(i);
1945 if (!kid.shouldRestart())
1946 continue;
1947
1948 if (!mainStartScriptCalled) {
1949 mainStartScript(masterCommand.arg0());
1950 mainStartScriptCalled = true;
1951 }
1952
1953 // These are only needed by the forked child below, but let's keep
1954 // them out of that "no man's land" between fork() and execvp().
1955 auto kidCommand = masterCommand;
1956 kidCommand.resetArg0(kid.processName().c_str());
1957 assert(!kidCommand.hasOption(optKid));
1958 kidCommand.pushFrontOption("--kid", kid.gist().c_str());
1959
1960 if ((pid = fork()) == 0) {
1961 /* child */
1962 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1963 (void)execvp(masterCommand.arg0(), kidCommand.argv());
1964 int xerrno = errno;
1965 syslog(LOG_ALERT, "execvp failed: %s", xstrerr(xerrno));
1966 }
1967
1968 kid.start(pid);
1969 syslog(LOG_NOTICE, "Squid Parent: %s process %d started",
1970 kid.processName().c_str(), pid);
1971 }
1972
1973 /* parent */
1974 openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
1975
1976 // If Squid received a signal while checking for dying kids (below) or
1977 // starting new kids (above), then do a fast check for a new dying kid
1978 // (WaitForAnyPid with the WNOHANG option) and continue to forward
1979 // signals to kids. Otherwise, wait for a kid to die or for a signal
1980 // to abort the blocking WaitForAnyPid() call.
1981 // With the WNOHANG option, we could check whether WaitForAnyPid() was
1982 // aborted by a dying kid or a signal, but it is not required: The
1983 // next do/while loop will check again for any dying kids.
1984 int waitFlag = 0;
1985 if (masterSignaled())
1986 waitFlag = WNOHANG;
1987 PidStatus status;
1988 pid = WaitForAnyPid(status, waitFlag);
1990
1991 // check for a stopped kid
1992 if (Kid *kid = pid > 0 ? TheKids.find(pid) : nullptr)
1993 kid->stop(status);
1994 else if (pid > 0)
1995 syslog(LOG_NOTICE, "Squid Parent: unknown child process %d exited", pid);
1996
1999
2001 leave_suid();
2002 // XXX: Master process has no main loop and, hence, should not call
2003 // RegisteredRunner::startShutdown which promises a loop iteration.
2005 enter_suid();
2006 masterExit();
2007 }
2008 }
2009
2010 /* NOTREACHED */
2011#endif /* _SQUID_WINDOWS_ */
2012
2013}
2014
2015static void
2017{
2018 /* XXX: This function is called after the main loop has quit, which
2019 * means that no AsyncCalls would be called, including close handlers.
2020 * TODO: We need to close/shut/free everything that needs calls before
2021 * exiting the loop.
2022 */
2023
2024#if USE_WIN32_SERVICE
2025 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2026#endif
2027
2028 debugs(1, Important(9), "Shutting down...");
2029#if USE_SSL_CRTD
2031#endif
2032#if USE_OPENSSL
2034#endif
2037 icpClosePorts();
2038#if USE_HTCP
2040#endif
2041#if SQUID_SNMP
2043#endif
2044#if USE_WCCP
2045
2047#endif
2048#if USE_WCCPv2
2049
2051#endif
2052
2055
2056#if USE_DELAY_POOLS
2058#endif
2059#if USE_AUTH
2061#endif
2062#if USE_WIN32_SERVICE
2063
2064 WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
2065#endif
2066#if ICAP_CLIENT
2068#endif
2069
2070 Store::Root().sync(); /* Flush pending object writes/unlinks */
2071
2072 unlinkdClose(); /* after sync/flush. NOP if !USE_UNLINKD */
2073
2075 PrintRusage();
2077 Store::Root().sync(); /* Flush log writes */
2078 storeLogClose();
2080 Store::Root().sync(); /* Flush log close */
2082
2083 fdDumpOpen();
2084
2085 comm_exit();
2086
2088
2089 memClean();
2090
2091 debugs(1, Important(10), "Squid Cache (Version " << version_string << "): Exiting normally.");
2092
2093 exit(shutdown_status);
2094}
2095
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: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 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: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:634
void add_http_port(char *portspec)
Definition: cache_cf.cc:3712
void self_destruct(void)
Definition: cache_cf.cc:276
void carpInit(void)
Definition: carp.cc:44
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: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:1091
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:85
static void SettleSyslog()
Definition: debug.cc:1141
static void UseCacheLog()
Definition: debug.cc:1121
static void BanCacheLogUse()
Definition: debug.cc:1114
static void ConfigureSyslog(const char *facility)
enables logging to syslog (using the specified facility, when not nil)
Definition: debug.cc:1079
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:253
static void initModule()
Definition: FwdState.cc:1393
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
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
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::@121 onoff
struct SquidConfig::@94 Port
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
static void Shutdown()
Shutdown helper structure.
Definition: helper.cc:233
static void Init()
Init helper structure.
Definition: helper.cc:172
static void Reconfigure()
Definition: helper.cc:250
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:119
static void Shutdown()
Shutdown helper structure.
Definition: helper.cc:108
struct StatCounters::@123 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
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:1162
void comm_exit(void)
Definition: comm.cc:1185
void commCloseAllSockets(void)
Definition: comm.cc:1466
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:90
#define Important(id)
Definition: Messages.h:91
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:193
#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:210
void asnInit(void)
Definition: Asn.cc:194
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: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:697
void icpClosePorts(void)
Definition: icp_v2.cc:804
void htcpOpenPorts(void)
Definition: htcp.cc:1443
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:1030
static void master_shutdown(int sig)
Shutdown signal handler for master process.
Definition: main.cc:742
static void StartUsingConfig()
Definition: main.cc:1413
static void watch_child(const CommandLine &)
Definition: main.cc:1851
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:1390
static int opt_signal_service
Definition: main.cc:143
int SquidMain(int argc, char **argv)
unsafe main routine – may throw
Definition: main.cc:1441
static void masterReviveKids()
Reacts to the kid revival alarm.
Definition: main.cc:1764
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:1815
int main(int argc, char **argv)
Definition: main.cc:1329
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:1362
static volatile int do_shutdown
Definition: main.cc:152
void rotate_logs(int sig)
Definition: main.cc:701
static void RunConfigUsers()
Definition: main.cc:1406
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:2016
void WINAPI SquidWinSvcMain(int argc, char **argv)
Definition: main.cc:1322
static void masterShutdownStart()
Initiates shutdown sequence. Shutdown ends when the last running kids stops.
Definition: main.cc:1734
static bool mainChangeDir(const char *dir)
changes working directory, providing error reporting
Definition: main.cc:1050
static void masterExit()
Definition: main.cc:1833
static void OnTerminate()
Definition: main.cc:1300
static int RotateSignal
Definition: main.cc:157
static int SquidMainSafe(int argc, char **argv)
unsafe main routine wrapper to catch exceptions
Definition: main.cc:1345
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:1674
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:1774
static volatile int shutdown_status
Definition: main.cc:154
static void masterMaintainKidRevivalSchedule()
Definition: main.cc:1797
bool Chrooted
Definition: main.cc:1063
static void mainStartScript(const char *prog)
Definition: main.cc:1704
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:1757
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:1744
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:1807
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: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 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:931
void Maintain(void *unused)
Definition: store.cc:1106
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:938
#define xfree
#define xstrdup
void neighbors_init(void)
Definition: neighbors.cc:557
void netdbInit(void)
Definition: net_db.cc:863
#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:69
void snmpOpenPorts(void)
Definition: snmp_core.cc:257
void snmpClosePorts(void)
Definition: snmp_core.cc:321
#define CACHE_ICP_PORT
Definition: squid.h:17
#define CACHE_HTTP_PORT
Definition: squid.h:16
void _db_rotate_log(void)
Definition: debug.cc:1156
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:1231
void storeFsInit(void)
Definition: store.cc:1604
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
#define NULL
Definition: types.h:160
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