------------------------------------------------------------ revno: 12343 [merge] revision-id: kinkie@squid-cache.org-20121005133819-519eed0mwuua69uf parent: squid3@treenet.co.nz-20121005102639-nfxo667u2x15e04v parent: kinkie@squid-cache.org-20121005132737-quv97o2hd7puvnn0 committer: Francesco Chemolli branch nick: trunk timestamp: Fri 2012-10-05 15:38:19 +0200 message: Move fatal family of functions to own implementation and stub files. ------------------------------------------------------------ Use --include-merges or -n0 to see merged revisions. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: kinkie@squid-cache.org-20121005133819-519eed0mwuua69uf # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: d74948ff19c36aa18d2fafca4081ae77cff0f2f9 # timestamp: 2012-10-05 13:53:22 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20121005102639-\ # nfxo667u2x15e04v # # Begin patch === modified file 'src/Makefile.am' --- src/Makefile.am 2012-09-25 15:36:18 +0000 +++ src/Makefile.am 2012-10-05 13:10:15 +0000 @@ -342,6 +342,8 @@ ExternalACLEntry.h \ FadingCounter.h \ FadingCounter.cc \ + fatal.h \ + fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -1116,6 +1118,8 @@ cbdata.cc \ cbdata.h \ ETag.cc \ + fatal.h \ + tests/stub_fatal.cc \ HttpBody.h \ HttpBody.cc \ HttpHeaderFieldStat.h \ @@ -1217,6 +1221,8 @@ DiskIO/WriteRequest.cc \ ETag.cc \ event.cc \ + fatal.h \ + tests/stub_fatal.cc \ FileMap.h \ filemap.cc \ HelperChildConfig.h \ @@ -1423,6 +1429,8 @@ event.cc \ external_acl.cc \ ExternalACLEntry.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -1616,6 +1624,8 @@ ETag.cc \ EventLoop.cc \ event.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ FileMap.h \ @@ -1821,6 +1831,8 @@ external_acl.cc \ ExternalACLEntry.cc \ FadingCounter.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -2061,6 +2073,8 @@ external_acl.cc \ ExternalACLEntry.cc \ FadingCounter.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -2298,6 +2312,8 @@ external_acl.cc \ ExternalACLEntry.cc \ FadingCounter.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -2586,6 +2602,8 @@ ETag.cc \ external_acl.cc \ ExternalACLEntry.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -2775,6 +2793,8 @@ ETag.cc \ event.cc \ EventLoop.cc \ + fatal.h \ + tests/stub_fatal.cc \ FileMap.h \ filemap.cc \ HttpHeaderFieldStat.h \ @@ -3001,6 +3021,8 @@ store_rebuild.h \ tests/stub_store_rebuild.cc \ tests/stub_store_stats.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ client_db.h \ @@ -3162,6 +3184,8 @@ ETag.cc \ EventLoop.cc \ event.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ FileMap.h \ @@ -3320,6 +3344,8 @@ store_rebuild.h \ tests/stub_store_rebuild.cc \ tests/stub_store_stats.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ disk.h \ @@ -3655,6 +3681,8 @@ event.cc \ external_acl.cc \ ExternalACLEntry.cc \ + fatal.h \ + tests/stub_fatal.cc \ fd.h \ fd.cc \ fde.cc \ @@ -3856,6 +3884,8 @@ MemBuf.cc \ String.cc \ ConfigParser.cc \ + fatal.h \ + tests/stub_fatal.cc \ tests/testMain.cc \ tests/testConfigParser.cc \ tests/testConfigParser.h \ === added file 'src/fatal.cc' --- src/fatal.cc 1970-01-01 00:00:00 +0000 +++ src/fatal.cc 2012-10-05 13:10:15 +0000 @@ -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(); +} + === renamed file 'include/fatal.h' => 'src/fatal.h' --- include/fatal.h 2012-08-30 14:18:27 +0000 +++ src/fatal.h 2012-10-05 13:10:15 +0000 @@ -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 */ === added file 'src/tests/stub_fatal.cc' --- src/tests/stub_fatal.cc 1970-01-01 00:00:00 +0000 +++ src/tests/stub_fatal.cc 2012-10-05 13:10:15 +0000 @@ -0,0 +1,39 @@ +/* + * 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" + +#define STUB_API "fatal.cc" +#include "tests/STUB.h" + +void fatal(const char *message) STUB +void fatal_common(const char *message) STUB +void fatalf(const char *fmt,...) STUB +void fatalvf(const char *fmt, va_list args) STUB +void fatal_dump(const char *message) STUB === modified file 'src/tests/stub_tools.cc' --- src/tests/stub_tools.cc 2012-09-03 08:42:58 +0000 +++ src/tests/stub_tools.cc 2012-10-05 13:10:15 +0000 @@ -17,11 +17,6 @@ void death(int sig) STUB void BroadcastSignalIfAny(int& sig) STUB void sigusr2_handle(int sig) STUB -void fatal(const char *message) STUB -void fatal_common(const char *message) STUB -void fatalf(const char *fmt,...) STUB -void fatalvf(const char *fmt, va_list args) STUB -void fatal_dump(const char *message) STUB void debug_trap(const char *message) STUB void sig_child(int sig) STUB void sig_shutdown(int sig) STUB === modified file 'src/tools.cc' --- src/tools.cc 2012-10-04 09:14:06 +0000 +++ src/tools.cc 2012-10-04 13:01:09 +0000 @@ -78,8 +78,6 @@ \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 @@ #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) { === modified file 'test-suite/Makefile.am' --- test-suite/Makefile.am 2012-01-07 10:15:40 +0000 +++ test-suite/Makefile.am 2012-10-05 13:10:15 +0000 @@ -53,7 +53,7 @@ tcp_banger2_LDADD = $(top_builddir)/lib/libmiscutil.la -DEBUG_SOURCE = test_tools.cc stub_debug.cc stub_tools.cc +DEBUG_SOURCE = test_tools.cc stub_debug.cc stub_tools.cc stub_fatal.cc stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc cp $(top_srcdir)/src/tests/stub_debug.cc . @@ -61,7 +61,10 @@ stub_tools.cc: $(top_srcdir)/src/tests/stub_tools.cc cp $(top_srcdir)/src/tests/stub_tools.cc . -CLEANFILES += stub_debug.cc stub_tools.cc +stub_fatal.cc: $(top_srcdir)/src/tests/stub_fatal.cc + cp $(top_srcdir)/src/tests/stub_fatal.cc . + +CLEANFILES += stub_debug.cc stub_tools.cc stub_fatal.cc ## XXX: somewhat broken. Its meant to test our debugs() implementation. ## but it has never been linked to the actual src/debug.cc implementation !!