From 6249367873059fd0bd2ac44a05e9eb306eb03f76 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sun, 12 Apr 2009 20:17:19 +1200 Subject: [PATCH] Detatch debugs() from many of its dependencies - makes cache.log independent of the other logging systems - adds debug_options rotate=N setting - moves debug-specific globals and types into Debug:: TODO: remove remaining dependancy on shutdown flag polish up namespace etc for libdebug --- doc/release-notes/release-3.1.sgml | 8 ++- src/Debug.h | 10 ++++ src/cache_cf.cc | 5 +- src/cf.data.pre | 96 +++++++++++++++++------------- src/debug.cc | 75 ++++++++++++----------- src/globals.h | 6 -- src/ipc.cc | 4 +- src/ipc_win32.cc | 4 +- src/main.cc | 22 ++++--- src/snmp_agent.cc | 2 +- src/structs.h | 3 - src/tools.cc | 4 +- src/typedefs.h | 3 - 13 files changed, 129 insertions(+), 113 deletions(-) diff --git a/doc/release-notes/release-3.1.sgml b/doc/release-notes/release-3.1.sgml index dce25cba7b..a0fb0a1769 100644 --- a/doc/release-notes/release-3.1.sgml +++ b/doc/release-notes/release-3.1.sgml @@ -871,6 +871,10 @@ NOCOMMENT_START on error pages if used. + debug_options rotate= +

New parameter rotate=N to control number of cache.log rotations independent of other logs. + + external_acl_type

New options 'ipv4' and 'ipv6' are added to set the IPv4/v6 protocol between squid and its helpers. Please be aware of some limits to these options. These options only affet the transport protocol used @@ -949,6 +953,9 @@ NOCOMMENT_START https_port intercept sslbump connection-auth[=on|off]

New port options. see http_port. + logfile_rotate +

No longer controls cache.log rotation. Use debug_options rotate=N instead. + maximum_object_size_in_memory

Default size limit increased to 512KB. @@ -1009,7 +1016,6 @@ refresh_pattern . 0 20% 4320

Method names now accepted. Replacing the old magic numbers. '1' becomes 'gre' and '2' becomes 'l2' - diff --git a/src/Debug.h b/src/Debug.h index 2322bb5228..a4f1fcf21e 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -51,6 +51,9 @@ #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__)) #endif +/* context-based debugging, the actual type is subject to change */ +typedef int Ctx; + /* defined debug section limits */ #define MAX_DEBUG_SECTIONS 100 @@ -64,8 +67,15 @@ class Debug { public: + static char *debugOptions; + static char *cache_log; + static int rotateNumber; static int Levels[MAX_DEBUG_SECTIONS]; static int level; + static int override_X; + static int log_stderr; + static bool log_syslog; + static std::ostream &getDebugOut(); static void finishDebug(); static void parseOptions(char const *); diff --git a/src/cache_cf.cc b/src/cache_cf.cc index cfd990d4c7..b9db3e9e78 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -403,7 +403,7 @@ parseConfigFile(const char *file_name) if (!Config.chroot_dir) { leave_suid(); setUmask(Config.umask); - _db_init(Config.Log.log, Config.debugOptions); + _db_init(Debug::cache_log, Debug::debugOptions); enter_suid(); } @@ -494,9 +494,6 @@ configDoConfigure(void) else Config.appendDomainLen = 0; - safe_free(debug_options) - debug_options = xstrdup(Config.debugOptions); - if (Config.retry.maxtries > 10) fatal("maximum_single_addr_tries cannot be larger than 10"); diff --git a/src/cf.data.pre b/src/cf.data.pre index 1610005464..cd685c4c4f 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2382,17 +2382,6 @@ DOC_START logging will also not be accounted for in performance counters. DOC_END -NAME: cache_log -TYPE: string -DEFAULT: none -DEFAULT_IF_NONE: @DEFAULT_CACHE_LOG@ -LOC: Config.Log.log -DOC_START - Cache logging file. This is where general information about - your cache's behavior goes. You can increase the amount of data - logged to this file with the "debug_options" tag below. -DOC_END - NAME: cache_store_log TYPE: string DEFAULT: none @@ -2460,6 +2449,9 @@ DOC_START purposes, so -k rotate uses another signal. It is best to get in the habit of using 'squid -k rotate' instead of 'kill -USR1 '. + + Note, from Squid-3.1 this option has no effect on the cache.log, + that log can be rotated separately by using debug_options DOC_END NAME: emulate_httpd_log @@ -2541,19 +2533,6 @@ DOC_START A filename to write the process-id to. To disable, enter "none". DOC_END -NAME: debug_options -TYPE: eol -DEFAULT: ALL,1 -LOC: Config.debugOptions -DOC_START - Logging options are set as section,level where each source file - is assigned a unique section. Lower levels result in less - output, Full debugging (level 9) can result in a very large - log file, so be careful. The magic word "ALL" sets debugging - levels for all sections. We recommend normally running with - "ALL,1". -DOC_END - NAME: log_fqdn COMMENT: on|off TYPE: onoff @@ -2621,6 +2600,58 @@ DOC_START To disable, enter "none". DOC_END +COMMENT_START + OPTIONS FOR TROUBLESHOOTING + ----------------------------------------------------------------------------- +COMMENT_END + +NAME: cache_log +TYPE: string +DEFAULT: none +DEFAULT_IF_NONE: @DEFAULT_CACHE_LOG@ +LOC: Debug::cache_log +DOC_START + Cache logging file. This is where general information about + your cache's behavior goes. You can increase the amount of data + logged to this file and how often its rotated with "debug_options" +DOC_END + +NAME: debug_options +TYPE: eol +DEFAULT: rotate=1 ALL,1 +LOC: Debug::debugOptions +DOC_START + Logging options are set as section,level where each source file + is assigned a unique section. Lower levels result in less + output, Full debugging (level 9) can result in a very large + log file, so be careful. + + The magic word "ALL" sets debugging levels for all sections. + We recommend normally running with "ALL,1". + + The rotate= option can be increased to keep more of these logs. + For most uses a single log should be enough to monitor current + events affecting Squid. +DOC_END + +NAME: coredump_dir +TYPE: string +LOC: Config.coredump_dir +DEFAULT: none +DEFAULT_IF_NONE: none +DOC_START + By default Squid leaves core files in the directory from where + it was started. If you set 'coredump_dir' to a directory + that exists, Squid will chdir() to that directory at startup + and coredump files will be left there. + +NOCOMMENT_START +# Leave coredumps in the first cache dir +coredump_dir @DEFAULT_SWAP_DIR@ +NOCOMMENT_END +DOC_END + + COMMENT_START OPTIONS FOR FTP GATEWAYING ----------------------------------------------------------------------------- @@ -5936,23 +5967,6 @@ DOC_START violation. DOC_END -NAME: coredump_dir -TYPE: string -LOC: Config.coredump_dir -DEFAULT: none -DEFAULT_IF_NONE: none -DOC_START - By default Squid leaves core files in the directory from where - it was started. If you set 'coredump_dir' to a directory - that exists, Squid will chdir() to that directory at startup - and coredump files will be left there. - -NOCOMMENT_START -# Leave coredumps in the first cache dir -coredump_dir @DEFAULT_SWAP_DIR@ -NOCOMMENT_END -DOC_END - NAME: chroot TYPE: string LOC: Config.chroot_dir diff --git a/src/debug.cc b/src/debug.cc index fbb07ae4ad..6a26ee0f19 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -35,12 +35,24 @@ #include "config.h" #include "Debug.h" #include "SquidTime.h" +#include "util.h" -/* for Config */ -#include "structs.h" +/* for shutting_down flag in xassert() */ +#include "globals.h" +/* cope with no squid.h */ +#ifndef MAXPATHLEN +#define MAXPATHLEN 256 +#endif + +char *Debug::debugOptions = NULL; +int Debug::override_X = 0; +int Debug::log_stderr = -1; +bool Debug::log_syslog = false; int Debug::Levels[MAX_DEBUG_SECTIONS]; int Debug::level; +char *Debug::cache_log = NULL; +int Debug::rotateNumber = 1; FILE *debug_log = NULL; static char *debug_log_file = NULL; static int Ctx_Lock = 0; @@ -63,7 +75,7 @@ typedef BOOL (WINAPI * PFInitializeCriticalSectionAndSpinCount) (LPCRITICAL_SECT void _db_print(const char *format,...) { - LOCAL_ARRAY(char, f, BUFSIZ); + char f[BUFSIZ]; f[0]='\0'; va_list args1; va_list args2; va_list args3; @@ -140,15 +152,13 @@ _db_print_file(const char *format, va_list args) ctx_print(); vfprintf(debug_log, format, args); - -//*AYJ:*/ if (!Config.onoff.buffered_logs) fflush(debug_log); } static void _db_print_stderr(const char *format, va_list args) { - if (opt_debug_stderr < Debug::level) + if (Debug::log_stderr < Debug::level) return; if (debug_log == stderr) @@ -161,15 +171,15 @@ _db_print_stderr(const char *format, va_list args) static void _db_print_syslog(const char *format, va_list args) { - LOCAL_ARRAY(char, tmpbuf, BUFSIZ); /* level 0,1 go to syslog */ if (Debug::level > 1) return; - if (0 == opt_syslog_enable) + if (!Debug::log_syslog) return; + char tmpbuf[BUFSIZ]; tmpbuf[0] = '\0'; vsnprintf(tmpbuf, BUFSIZ, format, args); @@ -178,7 +188,6 @@ _db_print_syslog(const char *format, va_list args) syslog(Debug::level == 0 ? LOG_WARNING : LOG_NOTICE, "%s", tmpbuf); } - #endif /* HAVE_SYSLOG */ static void @@ -188,12 +197,15 @@ debugArg(const char *arg) int l = 0; int i; - if (!strncasecmp(arg, "ALL", 3)) { + if (!strncasecmp(arg, "rotate=", 7)) { + arg += 7; + Debug::rotateNumber = atoi(arg); + return; + } else if (!strncasecmp(arg, "ALL", 3)) { s = -1; arg += 4; } else { s = atoi(arg); - while (*arg && *arg++ != ','); } @@ -370,7 +382,8 @@ syslog_facility_names[] = { void _db_set_syslog(const char *facility) { - opt_syslog_enable = 1; + Debug::log_syslog = true; + #ifdef LOG_LOCAL4 #ifdef LOG_DAEMON @@ -378,7 +391,7 @@ _db_set_syslog(const char *facility) #else syslog_facility = LOG_LOCAL4; -#endif +#endif /* LOG_DAEMON */ if (facility) { @@ -399,7 +412,7 @@ _db_set_syslog(const char *facility) if (facility) fprintf(stderr, "syslog facility type not supported on your system\n"); -#endif +#endif /* LOG_LOCAL4 */ } #endif @@ -411,7 +424,7 @@ Debug::parseOptions(char const *options) char *p = NULL; char *s = NULL; - if (Config.onoff.debug_override_X) { + if (override_X) { debugs(0, 9, "command-line -X overrides: " << options); return; } @@ -438,7 +451,7 @@ _db_init(const char *logfile, const char *options) #if HAVE_SYSLOG && defined(LOG_LOCAL4) - if (opt_syslog_enable) + if (Debug::log_syslog) openlog(APP_SHORTNAME, LOG_PID | LOG_NDELAY | LOG_CONS, syslog_facility); #endif /* HAVE_SYSLOG */ @@ -448,42 +461,36 @@ _db_init(const char *logfile, const char *options) void _db_rotate_log(void) { - int i; - LOCAL_ARRAY(char, from, MAXPATHLEN); - LOCAL_ARRAY(char, to, MAXPATHLEN); -#ifdef S_ISREG - - struct stat sb; -#endif - if (debug_log_file == NULL) return; #ifdef S_ISREG - + struct stat sb; if (stat(debug_log_file, &sb) == 0) if (S_ISREG(sb.st_mode) == 0) return; - #endif + char from[MAXPATHLEN]; + from[0] = '\0'; + + char to[MAXPATHLEN]; + to[0] = '\0'; + /* * NOTE: we cannot use xrename here without having it in a * separate file -- tools.c has too many dependencies to be * used everywhere debug.c is used. */ /* Rotate numbers 0 through N up one */ - for (i = Config.Log.rotateNumber; i > 1;) { + for (int i = Debug::rotateNumber; i > 1;) { i--; snprintf(from, MAXPATHLEN, "%s.%d", debug_log_file, i - 1); snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, i); #ifdef _SQUID_MSWIN_ - remove (to); - #endif - rename(from, to); } @@ -494,25 +501,21 @@ _db_rotate_log(void) #ifdef _SQUID_MSWIN_ if (debug_log != stderr) fclose(debug_log); - #endif /* Rotate the current log to .0 */ - if (Config.Log.rotateNumber > 0) { + if (Debug::rotateNumber > 0) { snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, 0); #ifdef _SQUID_MSWIN_ - remove (to); - #endif - rename(debug_log_file, to); } /* Close and reopen the log. It may have been renamed "manually" * before HUP'ing us. */ if (debug_log != stderr) - debugOpenLog(Config.Log.log); + debugOpenLog(Debug::cache_log); } static const char * diff --git a/src/globals.h b/src/globals.h index 2e679e9f4f..7ed98b6ac1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -58,7 +58,6 @@ extern "C" extern const char *dns_error_message; /* NULL */ extern const char *log_tags[]; extern char tmp_error_buf[ERROR_BUF_SZ]; - extern char *volatile debug_options; /* NULL */ extern char ThisCache[RFC2181_MAXHOSTNAMELEN << 1]; extern char ThisCache2[RFC2181_MAXHOSTNAMELEN << 1]; extern char config_input_line[BUFSIZ]; @@ -93,14 +92,9 @@ extern "C" //DEAD extern int icmp_sock; /* -1 */ extern int neighbors_do_private_keys; /* 1 */ extern int opt_catch_signals; /* 1 */ - extern int opt_debug_stderr; /* -1 */ extern int opt_foreground_rebuild; /* 0 */ extern char *opt_forwarded_for; /* NULL */ extern int opt_reload_hit_only; /* 0 */ -#if HAVE_SYSLOG - - extern int opt_syslog_enable; /* 0 */ -#endif extern int opt_udp_hit_obj; /* 0 */ extern int opt_create_swap_dirs; /* 0 */ diff --git a/src/ipc.cc b/src/ipc.cc index 3ead5bc42f..e886e95710 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -65,8 +65,8 @@ PutEnvironment() #if HAVE_PUTENV char *env_str; int tmp_s; - env_str = (char *)xcalloc((tmp_s = strlen(Config.debugOptions) + 32), 1); - snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Config.debugOptions); + env_str = (char *)xcalloc((tmp_s = strlen(Debug::debugOptions) + 32), 1); + snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Debug::debugOptions); putenv(env_str); #endif } diff --git a/src/ipc_win32.cc b/src/ipc_win32.cc index bec30bf8c7..77a354a293 100644 --- a/src/ipc_win32.cc +++ b/src/ipc_win32.cc @@ -98,8 +98,8 @@ PutEnvironment() #if HAVE_PUTENV char *env_str; int tmp_s; - env_str = (char *)xcalloc((tmp_s = strlen(Config.debugOptions) + 32), 1); - snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Config.debugOptions); + env_str = (char *)xcalloc((tmp_s = strlen(Debug::debugOptions) + 32), 1); + snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Debug::debugOptions); putenv(env_str); #endif } diff --git a/src/main.cc b/src/main.cc index 37ee8016ec..f044b0be41 100644 --- a/src/main.cc +++ b/src/main.cc @@ -329,8 +329,8 @@ mainParseOptions(int argc, char *argv[]) case 'X': /** \par X * Force full debugging */ - Debug::parseOptions("debug_options ALL,9"); - Config.onoff.debug_override_X = 1; + Debug::parseOptions("rotate=0 ALL,9"); + Debug::override_X = 1; sigusr2_handle(SIGUSR2); break; @@ -357,8 +357,8 @@ mainParseOptions(int argc, char *argv[]) case 'd': /** \par d - * Set global option opt_debug_stderr to the number given follwoign the option */ - opt_debug_stderr = atoi(optarg); + * Set global option Debug::log_stderr to the number given follwoign the option */ + Debug::log_stderr = atoi(optarg); break; case 'f': @@ -525,11 +525,9 @@ mainParseOptions(int argc, char *argv[]) case 'z': /** \par z - * Set global option opt_debug_stderr and opt_create_swap_dirs */ - opt_debug_stderr = 1; - + * Set global option Debug::log_stderr and opt_create_swap_dirs */ + Debug::log_stderr = 1; opt_create_swap_dirs = 1; - break; case 'h': @@ -715,7 +713,7 @@ mainReconfigureFinish(void *) setUmask(Config.umask); Mem::Report(); setEffectiveUser(); - _db_init(Config.Log.log, Config.debugOptions); + _db_init(Debug::cache_log, Debug::debugOptions); ipcache_restart(); /* clear stuck entries */ authenticateUserCacheRestart(); /* clear stuck ACL entries */ fqdncache_restart(); /* sigh, fqdncache too */ @@ -871,9 +869,9 @@ mainInitialize(void) if (icpPortNumOverride != 1) Config.Port.icp = (u_short) icpPortNumOverride; - _db_init(Config.Log.log, Config.debugOptions); + _db_init(Debug::cache_log, Debug::debugOptions); - fd_open(fileno(debug_log), FD_LOG, Config.Log.log); + fd_open(fileno(debug_log), FD_LOG, Debug::cache_log); #if MEM_GEN_TRACE @@ -1548,7 +1546,7 @@ watch_child(char *argv[]) dup2(nullfd, 0); - if (opt_debug_stderr < 0) { + if (Debug::log_stderr < 0) { dup2(nullfd, 1); dup2(nullfd, 2); } diff --git a/src/snmp_agent.cc b/src/snmp_agent.cc index dfa4265e4a..eea994aed5 100644 --- a/src/snmp_agent.cc +++ b/src/snmp_agent.cc @@ -156,7 +156,7 @@ snmp_confFn(variable_list * Var, snint * ErrP) case CONF_LOG_FAC: Answer = snmp_var_new(Var->name, Var->name_length); - if (!(cp = Config.debugOptions)) + if (!(cp = Debug::debugOptions)) cp = "None"; Answer->type = ASN_OCTET_STR; diff --git a/src/structs.h b/src/structs.h index e83b11b74c..d4b9a9f24f 100644 --- a/src/structs.h +++ b/src/structs.h @@ -248,7 +248,6 @@ struct SquidConfig { char *as_whois_server; struct { - char *log; char *store; char *swap; #if USE_USERAGENT_LOG @@ -314,7 +313,6 @@ struct SquidConfig { } Accel; char *appendDomain; size_t appendDomainLen; - char *debugOptions; char *pidFilename; char *netdbFilename; char *mimeTablePathname; @@ -436,7 +434,6 @@ struct SquidConfig { int httpd_suppress_version_string; int global_internal_static; int dns_require_A; - int debug_override_X; #if FOLLOW_X_FORWARDED_FOR int acl_uses_indirect_client; diff --git a/src/tools.cc b/src/tools.cc index 85d3fa24c9..e83e5159a4 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -419,7 +419,7 @@ sigusr2_handle(int sig) state = 1; } else { #ifndef MEM_GEN_TRACE - Debug::parseOptions(Config.debugOptions); + Debug::parseOptions(Debug::debugOptions); #else log_trace_init("/tmp/squid.alloc"); @@ -444,7 +444,7 @@ fatal_common(const char *message) fprintf(debug_log, "FATAL: %s\n", message); - if (opt_debug_stderr > 0 && debug_log != stderr) + if (Debug::log_stderr > 0 && debug_log != stderr) fprintf(stderr, "FATAL: %s\n", message); fprintf(debug_log, "Squid Cache (Version %s): Terminated abnormally.\n", diff --git a/src/typedefs.h b/src/typedefs.h index d191c39040..0452f7b2aa 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -235,9 +235,6 @@ typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, i /* MD5 cache keys */ typedef unsigned char cache_key; -/* context-based debugging, the actual type is subject to change */ -typedef int Ctx; - /* in case we want to change it later */ typedef ssize_t mb_size_t; -- 2.39.5