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
16static void
17fatal_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
23
25}
26
27void
28fatal(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 */
58static void
59fatalvf(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 */
67void
68fatalf(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 */
77void
78fatal_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
int storeDirWriteCleanLogs(int reopen)
Definition: Disks.cc:699
static void PrepareToDie()
Definition: debug.cc:562
void(* failure_notify)(const char *)
Definition: compat.cc:12
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
#define BUFSIZ
Definition: defines.h:20
static void fatal_common(const char *message)
Definition: fatal.cc:17
void fatal(const char *message)
Definition: fatal.cc:28
static void fatalvf(const char *fmt, va_list args)
Definition: fatal.cc:59
void fatal_dump(const char *message)
Definition: fatal.cc:78
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
int shutting_down
const char * version_string
int opt_catch_signals
std::ostream & ForceAlert(std::ostream &s)
Definition: debug.cc:1408
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 leave_suid(void)
Definition: tools.cc:559
void PrintRusage(void)
Definition: tools.cc:329
void dumpMallocStats(void)
Definition: tools.cc:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors