]>
Commit | Line | Data |
---|---|---|
94739d08 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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" | |
675b8408 | 10 | #include "debug/Stream.h" |
94739d08 FC |
11 | #include "fatal.h" |
12 | #include "globals.h" | |
2745fea5 | 13 | #include "store/Disks.h" |
94739d08 FC |
14 | #include "tools.h" |
15 | ||
94739d08 FC |
16 | static void |
17 | fatal_common(const char *message) | |
18 | { | |
e863656d CT |
19 | debugs(1, DBG_CRITICAL, ForceAlert << "FATAL: " << message); |
20 | debugs(1, DBG_CRITICAL, "Squid Cache (Version " << version_string << "): Terminated abnormally."); | |
94739d08 FC |
21 | |
22 | PrintRusage(); | |
23 | ||
24 | dumpMallocStats(); | |
25 | } | |
26 | ||
94739d08 FC |
27 | void |
28 | fatal(const char *message) | |
29 | { | |
30 | /* suppress secondary errors from the dying */ | |
31 | shutting_down = 1; | |
32 | ||
33 | releaseServerSockets(); | |
94739d08 FC |
34 | |
35 | /* XXX: this should be turned into a callback-on-fatal, or | |
36 | * a mandatory-shutdown-event or something like that. | |
37 | * - RBC 20060819 | |
38 | */ | |
39 | ||
40 | /* | |
41 | * DPW 2007-07-06 | |
42 | * Call leave_suid() here to make sure that swap.state files | |
43 | * are written as the effective user, rather than root. Squid | |
44 | * may take on root privs during reconfigure. If squid.conf | |
45 | * contains a "Bungled" line, fatal() will be called when the | |
46 | * process still has root privs. | |
47 | */ | |
48 | leave_suid(); | |
49 | ||
2745fea5 | 50 | storeDirWriteCleanLogs(0); |
94739d08 FC |
51 | |
52 | fatal_common(message); | |
53 | ||
24885773 | 54 | exit(EXIT_FAILURE); |
94739d08 FC |
55 | } |
56 | ||
57 | /* used by fatalf */ | |
58 | static void | |
59 | fatalvf(const char *fmt, va_list args) | |
60 | { | |
61 | static char fatal_str[BUFSIZ]; | |
62 | vsnprintf(fatal_str, sizeof(fatal_str), fmt, args); | |
63 | fatal(fatal_str); | |
64 | } | |
65 | ||
66 | /* printf-style interface for fatal */ | |
67 | void | |
68 | fatalf(const char *fmt,...) | |
69 | { | |
70 | va_list args; | |
71 | va_start(args, fmt); | |
72 | fatalvf(fmt, args); | |
73 | va_end(args); | |
74 | } | |
75 | ||
76 | /* fatal with dumping core */ | |
77 | void | |
78 | fatal_dump(const char *message) | |
79 | { | |
aee3523a | 80 | failure_notify = nullptr; |
94739d08 FC |
81 | releaseServerSockets(); |
82 | ||
83 | if (message) | |
84 | fatal_common(message); | |
85 | ||
86 | /* | |
87 | * Call leave_suid() here to make sure that swap.state files | |
88 | * are written as the effective user, rather than root. Squid | |
89 | * may take on root privs during reconfigure. If squid.conf | |
90 | * contains a "Bungled" line, fatal() will be called when the | |
91 | * process still has root privs. | |
92 | */ | |
93 | leave_suid(); | |
94 | ||
95 | if (opt_catch_signals) | |
96 | storeDirWriteCleanLogs(0); | |
97 | ||
61be1d8e | 98 | Debug::PrepareToDie(); |
94739d08 FC |
99 | abort(); |
100 | } | |
101 |