]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fatal.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / fatal.cc
CommitLineData
94739d08 1/*
2cd0bda2 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
94739d08 3 *
bbc27441
AJ
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.
94739d08
FC
7 */
8
9#include "squid.h"
10#include "Debug.h"
11#include "fatal.h"
12#include "globals.h"
2745fea5 13#include "store/Disks.h"
94739d08
FC
14#include "tools.h"
15
94739d08
FC
16static void
17fatal_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
94739d08
FC
38void
39fatal(const char *message)
40{
41 /* suppress secondary errors from the dying */
42 shutting_down = 1;
43
44 releaseServerSockets();
94739d08
FC
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
2745fea5 61 storeDirWriteCleanLogs(0);
94739d08
FC
62
63 fatal_common(message);
64
65 exit(1);
66}
67
68/* used by fatalf */
69static void
70fatalvf(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 */
78void
79fatalf(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 */
88void
89fatal_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