]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Moved fatal functions out of tools.cc and into own source file in lib/fatal.cc
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 4 Oct 2012 13:01:09 +0000 (15:01 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 4 Oct 2012 13:01:09 +0000 (15:01 +0200)
include/fatal.h
lib/Makefile.am
lib/fatal.cc [new file with mode: 0644]
src/tools.cc

index 26ce8b2600528e876d988016f2b0ef3014f3728b..79a3e2cd7a6a6da6717446ba8affd28872b0fd94 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef SQUID_FATAL_H
 #define SQUID_FATAL_H
 
-extern void fatal(const char *message);
-extern void fatalf(const char *fmt,...) PRINTF_FORMAT_ARG1;
-extern void fatal_dump(const char *message);
+void fatal(const char *message);
+void fatalf(const char *fmt,...) PRINTF_FORMAT_ARG1;
+void fatal_dump(const char *message);
 
 #endif /* SQUID_FATAL_H */
index 913013879983960b8172f6720c0ad3c1cb18f090..a0a9840e715782ce1d9b0febed2de7020ed99f8c 100644 (file)
@@ -69,7 +69,8 @@ libmiscutil_la_SOURCES = \
        Splay.cc \
        stub_memaccount.c \
        util.c \
-       xusleep.c
+       xusleep.c \
+       fatal.cc
 
 # $(top_srcdir)/include/version.h should be a dependency
 libsspwin32_la_SOURCES = \
diff --git a/lib/fatal.cc b/lib/fatal.cc
new file mode 100644 (file)
index 0000000..3660464
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "squid.h"
+#include "Debug.h"
+#include "fatal.h"
+#include "globals.h"
+#include "SwapDir.h"
+#include "tools.h"
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+static void
+fatal_common(const char *message)
+{
+#if HAVE_SYSLOG
+    syslog(LOG_ALERT, "%s", message);
+#endif
+
+    fprintf(debug_log, "FATAL: %s\n", message);
+
+    if (Debug::log_stderr > 0 && debug_log != stderr)
+        fprintf(stderr, "FATAL: %s\n", message);
+
+    fprintf(debug_log, "Squid Cache (Version %s): Terminated abnormally.\n",
+            version_string);
+
+    fflush(debug_log);
+
+    PrintRusage();
+
+    dumpMallocStats();
+}
+
+
+void
+fatal(const char *message)
+{
+    /* suppress secondary errors from the dying */
+    shutting_down = 1;
+
+    releaseServerSockets();
+    /* check for store_dirs_rebuilding because fatal() is often
+     * used in early initialization phases, long before we ever
+     * get to the store log. */
+
+    /* XXX: this should be turned into a callback-on-fatal, or
+     * a mandatory-shutdown-event or something like that.
+     * - RBC 20060819
+     */
+
+    /*
+     * DPW 2007-07-06
+     * Call leave_suid() here to make sure that swap.state files
+     * are written as the effective user, rather than root.  Squid
+     * may take on root privs during reconfigure.  If squid.conf
+     * contains a "Bungled" line, fatal() will be called when the
+     * process still has root privs.
+     */
+    leave_suid();
+
+    if (0 == StoreController::store_dirs_rebuilding)
+        storeDirWriteCleanLogs(0);
+
+    fatal_common(message);
+
+    exit(1);
+}
+
+/* used by fatalf */
+static void
+fatalvf(const char *fmt, va_list args)
+{
+    static char fatal_str[BUFSIZ];
+    vsnprintf(fatal_str, sizeof(fatal_str), fmt, args);
+    fatal(fatal_str);
+}
+
+/* printf-style interface for fatal */
+void
+fatalf(const char *fmt,...)
+{
+    va_list args;
+    va_start(args, fmt);
+    fatalvf(fmt, args);
+    va_end(args);
+}
+
+/* fatal with dumping core */
+void
+fatal_dump(const char *message)
+{
+    failure_notify = NULL;
+    releaseServerSockets();
+
+    if (message)
+        fatal_common(message);
+
+    /*
+     * Call leave_suid() here to make sure that swap.state files
+     * are written as the effective user, rather than root.  Squid
+     * may take on root privs during reconfigure.  If squid.conf
+     * contains a "Bungled" line, fatal() will be called when the
+     * process still has root privs.
+     */
+    leave_suid();
+
+    if (opt_catch_signals)
+        storeDirWriteCleanLogs(0);
+
+    abort();
+}
+
index 9b0a5d577daefae21655617ba892078ec9fe39bb..61706628317ac6456d9e50ca1699166a04282089 100644 (file)
@@ -78,8 +78,6 @@ and report the trace back to squid-bugs@squid-cache.org.\n\
 \n\
 Thanks!\n"
 
-static void fatal_common(const char *);
-static void fatalvf(const char *fmt, va_list args);
 static void mail_warranty(void);
 #if MEM_GEN_TRACE
 void log_trace_done();
@@ -446,107 +444,6 @@ sigusr2_handle(int sig)
 #endif
 }
 
-static void
-fatal_common(const char *message)
-{
-#if HAVE_SYSLOG
-    syslog(LOG_ALERT, "%s", message);
-#endif
-
-    fprintf(debug_log, "FATAL: %s\n", message);
-
-    if (Debug::log_stderr > 0 && debug_log != stderr)
-        fprintf(stderr, "FATAL: %s\n", message);
-
-    fprintf(debug_log, "Squid Cache (Version %s): Terminated abnormally.\n",
-            version_string);
-
-    fflush(debug_log);
-
-    PrintRusage();
-
-    dumpMallocStats();
-}
-
-/* fatal */
-void
-fatal(const char *message)
-{
-    /* suppress secondary errors from the dying */
-    shutting_down = 1;
-
-    releaseServerSockets();
-    /* check for store_dirs_rebuilding because fatal() is often
-     * used in early initialization phases, long before we ever
-     * get to the store log. */
-
-    /* XXX: this should be turned into a callback-on-fatal, or
-     * a mandatory-shutdown-event or something like that.
-     * - RBC 20060819
-     */
-
-    /*
-     * DPW 2007-07-06
-     * Call leave_suid() here to make sure that swap.state files
-     * are written as the effective user, rather than root.  Squid
-     * may take on root privs during reconfigure.  If squid.conf
-     * contains a "Bungled" line, fatal() will be called when the
-     * process still has root privs.
-     */
-    leave_suid();
-
-    if (0 == StoreController::store_dirs_rebuilding)
-        storeDirWriteCleanLogs(0);
-
-    fatal_common(message);
-
-    exit(1);
-}
-
-/* printf-style interface for fatal */
-void
-fatalf(const char *fmt,...)
-{
-    va_list args;
-    va_start(args, fmt);
-    fatalvf(fmt, args);
-    va_end(args);
-}
-
-/* used by fatalf */
-static void
-fatalvf(const char *fmt, va_list args)
-{
-    static char fatal_str[BUFSIZ];
-    vsnprintf(fatal_str, sizeof(fatal_str), fmt, args);
-    fatal(fatal_str);
-}
-
-/* fatal with dumping core */
-void
-fatal_dump(const char *message)
-{
-    failure_notify = NULL;
-    releaseServerSockets();
-
-    if (message)
-        fatal_common(message);
-
-    /*
-     * Call leave_suid() here to make sure that swap.state files
-     * are written as the effective user, rather than root.  Squid
-     * may take on root privs during reconfigure.  If squid.conf
-     * contains a "Bungled" line, fatal() will be called when the
-     * process still has root privs.
-     */
-    leave_suid();
-
-    if (opt_catch_signals)
-        storeDirWriteCleanLogs(0);
-
-    abort();
-}
-
 void
 debug_trap(const char *message)
 {