]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fatal.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / fatal.cc
1 /*
2 * Copyright (C) 1996-2018 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 "store/Disks.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
46 /* XXX: this should be turned into a callback-on-fatal, or
47 * a mandatory-shutdown-event or something like that.
48 * - RBC 20060819
49 */
50
51 /*
52 * DPW 2007-07-06
53 * Call leave_suid() here to make sure that swap.state files
54 * are written as the effective user, rather than root. Squid
55 * may take on root privs during reconfigure. If squid.conf
56 * contains a "Bungled" line, fatal() will be called when the
57 * process still has root privs.
58 */
59 leave_suid();
60
61 storeDirWriteCleanLogs(0);
62
63 fatal_common(message);
64
65 exit(EXIT_FAILURE);
66 }
67
68 /* used by fatalf */
69 static void
70 fatalvf(const char *fmt, va_list args)
71 {
72 static char fatal_str[BUFSIZ];
73 vsnprintf(fatal_str, sizeof(fatal_str), fmt, args);
74 fatal(fatal_str);
75 }
76
77 /* printf-style interface for fatal */
78 void
79 fatalf(const char *fmt,...)
80 {
81 va_list args;
82 va_start(args, fmt);
83 fatalvf(fmt, args);
84 va_end(args);
85 }
86
87 /* fatal with dumping core */
88 void
89 fatal_dump(const char *message)
90 {
91 failure_notify = NULL;
92 releaseServerSockets();
93
94 if (message)
95 fatal_common(message);
96
97 /*
98 * Call leave_suid() here to make sure that swap.state files
99 * are written as the effective user, rather than root. Squid
100 * may take on root privs during reconfigure. If squid.conf
101 * contains a "Bungled" line, fatal() will be called when the
102 * process still has root privs.
103 */
104 leave_suid();
105
106 if (opt_catch_signals)
107 storeDirWriteCleanLogs(0);
108
109 abort();
110 }
111