fatal.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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",
30 
31  fflush(debug_log);
32 
33  PrintRusage();
34 
36 }
37 
38 void
39 fatal(const char *message)
40 {
41  /* suppress secondary errors from the dying */
42  shutting_down = 1;
43 
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 
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 {
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)
108 
109  abort();
110 }
111 
#define debug_log
change-avoidance macro; new code should call DebugStream() instead
Definition: Debug.h:106
void(* failure_notify)(const char *)
Definition: compat.cc:12
void releaseServerSockets(void) STUB_NOP char *dead_msg(void) STUB_RETVAL(NULL) void mail_warranty(void) STUB 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(NULL) const char *uniqueHostname(void) STUB_RETVAL(NULL) void leave_suid(void) STUB_NOP void enter_suid(void) STUB void no_suid(void) STUB bool IamMasterProcess()
Definition: stub_tools.cc:18
void fatalf(const char *fmt,...)
Definition: fatal.cc:79
void fatal_dump(const char *message)
Definition: fatal.cc:89
int shutting_down
Definition: testAddress.cc:36
void dumpMallocStats(void)
Definition: tools.cc:156
static int log_stderr
Definition: Debug.h:83
int opt_catch_signals
void leave_suid(void)
Definition: tools.cc:504
void fatal(const char *message)
Definition: fatal.cc:39
void PrintRusage(void)
Definition: tools.cc:275
int storeDirWriteCleanLogs(int reopen)
Definition: Disks.cc:572
#define BUFSIZ
Definition: defines.h:20
static void fatal_common(const char *message)
Definition: fatal.cc:17
static void fatalvf(const char *fmt, va_list args)
Definition: fatal.cc:70
const char * version_string
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors