]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fatal.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / fatal.cc
1 /*
2 * Copyright (C) 1996-2014 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 #include "squid.h"
10 #include "Debug.h"
11 #include "fatal.h"
12 #include "globals.h"
13 #include "SwapDir.h"
14 #include "tools.h"
15
16 static void
17 fatal_common(const char *message)
18 {
19 #if HAVE_SYSLOG
20 syslog(LOG_ALERT, "%s", message);
21 #endif
22
23 fprintf(debug_log, "FATAL: %s\n", message);
24
25 if (Debug::log_stderr > 0 && debug_log != stderr)
26 fprintf(stderr, "FATAL: %s\n", message);
27
28 fprintf(debug_log, "Squid Cache (Version %s): Terminated abnormally.\n",
29 version_string);
30
31 fflush(debug_log);
32
33 PrintRusage();
34
35 dumpMallocStats();
36 }
37
38 void
39 fatal(const char *message)
40 {
41 /* suppress secondary errors from the dying */
42 shutting_down = 1;
43
44 releaseServerSockets();
45 /* check for store_dirs_rebuilding because fatal() is often
46 * used in early initialization phases, long before we ever
47 * get to the store log. */
48
49 /* XXX: this should be turned into a callback-on-fatal, or
50 * a mandatory-shutdown-event or something like that.
51 * - RBC 20060819
52 */
53
54 /*
55 * DPW 2007-07-06
56 * Call leave_suid() here to make sure that swap.state files
57 * are written as the effective user, rather than root. Squid
58 * may take on root privs during reconfigure. If squid.conf
59 * contains a "Bungled" line, fatal() will be called when the
60 * process still has root privs.
61 */
62 leave_suid();
63
64 if (0 == StoreController::store_dirs_rebuilding)
65 storeDirWriteCleanLogs(0);
66
67 fatal_common(message);
68
69 exit(1);
70 }
71
72 /* used by fatalf */
73 static void
74 fatalvf(const char *fmt, va_list args)
75 {
76 static char fatal_str[BUFSIZ];
77 vsnprintf(fatal_str, sizeof(fatal_str), fmt, args);
78 fatal(fatal_str);
79 }
80
81 /* printf-style interface for fatal */
82 void
83 fatalf(const char *fmt,...)
84 {
85 va_list args;
86 va_start(args, fmt);
87 fatalvf(fmt, args);
88 va_end(args);
89 }
90
91 /* fatal with dumping core */
92 void
93 fatal_dump(const char *message)
94 {
95 failure_notify = NULL;
96 releaseServerSockets();
97
98 if (message)
99 fatal_common(message);
100
101 /*
102 * Call leave_suid() here to make sure that swap.state files
103 * are written as the effective user, rather than root. Squid
104 * may take on root privs during reconfigure. If squid.conf
105 * contains a "Bungled" line, fatal() will be called when the
106 * process still has root privs.
107 */
108 leave_suid();
109
110 if (opt_catch_signals)
111 storeDirWriteCleanLogs(0);
112
113 abort();
114 }
115