From: Francesco Chemolli Date: Thu, 4 Oct 2012 13:01:09 +0000 (+0200) Subject: Moved fatal functions out of tools.cc and into own source file in lib/fatal.cc X-Git-Tag: SQUID_3_3_0_1~29^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94739d08cbbf966d3207fca7582960fe2870db32;p=thirdparty%2Fsquid.git Moved fatal functions out of tools.cc and into own source file in lib/fatal.cc --- diff --git a/include/fatal.h b/include/fatal.h index 26ce8b2600..79a3e2cd7a 100644 --- a/include/fatal.h +++ b/include/fatal.h @@ -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 */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 9130138799..a0a9840e71 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index 0000000000..36604642e3 --- /dev/null +++ b/lib/fatal.cc @@ -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 +#endif +#if HAVE_STDLIB_H +#include +#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(); +} + diff --git a/src/tools.cc b/src/tools.cc index 9b0a5d577d..6170662831 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -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) {