]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Detatch debugs() from many of its dependencies
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 12 Apr 2009 08:17:19 +0000 (20:17 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 12 Apr 2009 08:17:19 +0000 (20:17 +1200)
 - 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

13 files changed:
doc/release-notes/release-3.1.sgml
src/Debug.h
src/cache_cf.cc
src/cf.data.pre
src/debug.cc
src/globals.h
src/ipc.cc
src/ipc_win32.cc
src/main.cc
src/snmp_agent.cc
src/structs.h
src/tools.cc
src/typedefs.h

index dce25cba7b468d050876e3341e64d527c3aad179..a0fb0a17691cf26d04a405e98a7dc85c4f0ba5a8 100644 (file)
@@ -871,6 +871,10 @@ NOCOMMENT_START
                  on error pages if used.
        </verb>
 
+       <tag>debug_options rotate=</tag>
+       <p>New parameter rotate=N to control number of cache.log rotations independent of other logs.
+
+
         <tag>external_acl_type</tag>
         <p>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
        <tag>https_port intercept sslbump connection-auth[=on|off]</tag>
        <p>New port options. see http_port.
 
+       <tag>logfile_rotate</tag>
+       <p>No longer controls cache.log rotation. Use debug_options rotate=N instead.
+
        <tag>maximum_object_size_in_memory</tag>
        <p>Default size limit increased to 512KB.
 
@@ -1009,7 +1016,6 @@ refresh_pattern .                    0   20%     4320
        <p>Method names now accepted. Replacing the old magic numbers.
           '1' becomes 'gre' and '2' becomes 'l2'
 
-
 </descrip>
 
 
index 2322bb52285fd928fa55c7880bcf2bf7c97f062b..a4f1fcf21e915f7020fb7ae433cdce01345852ed 100644 (file)
@@ -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 *);
index cfd990d4c717523f42223a03ecd2ff580bb2ccd7..b9db3e9e78bc66fd29329f470bed1ec208d27c15 100644 (file)
@@ -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");
 
index 1610005464dc1ac9269303b4b69165b8c4163197..cd685c4c4f663529c737a492bf167fb0820e4746 100644 (file)
@@ -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
        <pid>'.
+
+       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
index fbb07ae4adb91669821b63aab65fb34c54e143cc..6a26ee0f1962e0f9bdd06ce4ac481fb6ef378d2f 100644 (file)
 #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 *
index 2e679e9f4f2a4605c1f06b171e2401a6f2399554..7ed98b6ac10346616ef489356102c22bfbe06343 100644 (file)
@@ -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 */
index 3ead5bc42f6c66218aa838d7159f36fdad303be6..e886e9571070e638a9da9ece20d25c17adad7964 100644 (file)
@@ -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
 }
index bec30bf8c77bbf636cea8f701e5b9dec6167ac18..77a354a293df0fd0e4b1bc6459afa74f13342376 100644 (file)
@@ -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
 }
index 37ee8016ec4ff98b88ec9fbcf0dd2c9d3303b8e8..f044b0be4170d37643d1f96487db2a4e7d1d3356 100644 (file)
@@ -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);
     }
index dfa4265e4aa3985b295ed435fab57f25476fc234..eea994aed5ea2e4cb44df4e2e28e9c8324d4ab69 100644 (file)
@@ -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;
index e83b11b74c3971d939be39a3d6c1ccc8434b8c2e..d4b9a9f24f9b7358a183c9fa4b18949b364494c1 100644 (file)
@@ -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;
index 85d3fa24c9c20123df57a975e9b89eb9799cb8b3..e83e5159a49c0ee5fb9ee2bedbc98274708fc145 100644 (file)
@@ -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",
index d191c3904000059fc0e2d907bfcc8404a9f4231e..0452f7b2aa30612f0f88e9c3bacf5d383e2192bd 100644 (file)
@@ -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;