fatal.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 #include "squid.h"
10 #include "debug/Stream.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  debugs(1, DBG_CRITICAL, ForceAlert << "FATAL: " << message);
20  debugs(1, DBG_CRITICAL, "Squid Cache (Version " << version_string << "): Terminated abnormally.");
21 
22  PrintRusage();
23 
25 }
26 
27 void
28 fatal(const char *message)
29 {
30  /* suppress secondary errors from the dying */
31  shutting_down = 1;
32 
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 
51 
52  fatal_common(message);
53 
54  exit(EXIT_FAILURE);
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 {
80  failure_notify = nullptr;
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 
97 
99  abort();
100 }
101 
void fatal(const char *message)
Definition: fatal.cc:28
void dumpMallocStats(void)
Definition: tools.cc:166
static void fatal_common(const char *message)
Definition: fatal.cc:17
#define DBG_CRITICAL
Definition: Stream.h:37
#define BUFSIZ
Definition: defines.h:20
void(* failure_notify)(const char *)
Definition: compat.cc:12
std::ostream & ForceAlert(std::ostream &s)
Definition: debug.cc:1411
const char * version_string
void leave_suid(void)
Definition: tools.cc:559
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
void PrintRusage(void)
Definition: tools.cc:329
static void PrepareToDie()
Definition: debug.cc:563
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
static void fatalvf(const char *fmt, va_list args)
Definition: fatal.cc:59
void fatal_dump(const char *message)
Definition: fatal.cc:78
int storeDirWriteCleanLogs(int reopen)
Definition: Disks.cc:700
int shutting_down
int opt_catch_signals
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192

 

Introduction

Documentation

Support

Miscellaneous