]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
netdb_filename directive to specify location of netdb state file
authorhno <>
Thu, 27 Dec 2007 21:55:47 +0000 (21:55 +0000)
committerhno <>
Thu, 27 Dec 2007 21:55:47 +0000 (21:55 +0000)
was hardcoded to use the first cache_dir. This moves the default location
to the logs directory and may be overridden at compile time by setting
DEFAULT_NETDB_FILE

src/Makefile.am
src/cf.data.pre
src/net_db.cc
src/structs.h

index 7f6e4ff8529f3a284f969e4b142ce5d2c94ea43b..56f610f364bd1e1e2aea3f099c7f6ef7d5d12c47 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.am,v 1.195 2007/12/26 22:33:31 hno Exp $
+#  $Id: Makefile.am,v 1.196 2007/12/27 14:55:47 hno Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -1014,6 +1014,7 @@ DEFAULT_CACHE_LOG       = $(DEFAULT_LOG_PREFIX)/cache.log
 DEFAULT_ACCESS_LOG      = $(DEFAULT_LOG_PREFIX)/access.log
 DEFAULT_STORE_LOG       = $(DEFAULT_LOG_PREFIX)/store.log
 DEFAULT_PID_FILE        = $(DEFAULT_LOG_PREFIX)/squid.pid
+DEFAULT_NETDB_FILE      = $(DEFAULT_LOG_PREFIX)/netdb.state
 DEFAULT_SWAP_DIR        = $(localstatedir)/cache
 DEFAULT_PINGER         = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
 DEFAULT_UNLINKD                = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
@@ -1071,6 +1072,7 @@ cf.data: cf.data.pre Makefile
        s%@DEFAULT_ACCESS_LOG@%$(DEFAULT_ACCESS_LOG)%g;\
        s%@DEFAULT_STORE_LOG@%$(DEFAULT_STORE_LOG)%g;\
        s%@DEFAULT_PID_FILE@%$(DEFAULT_PID_FILE)%g;\
+       s%@DEFAULT_NETDB_FILE@%$(DEFAULT_NETDB_FILE)%g;\
        s%@DEFAULT_SWAP_DIR@%$(DEFAULT_SWAP_DIR)%g;\
        s%@DEFAULT_ICON_DIR@%$(DEFAULT_ICON_DIR)%g;\
        s%@DEFAULT_MIB_PATH@%$(DEFAULT_MIB_PATH)%g;\
index aa85737ceed407c0baa9fcfaa08cfcbf55d5b4f6..7d7f4d7d9ac1f451bd52e36f3da09ec922e5bdbd 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.489 2007/12/14 23:11:46 amosjeffries Exp $
+# $Id: cf.data.pre,v 1.490 2007/12/27 14:55:47 hno Exp $
 #
 # SQUID Web Proxy Cache                http://www.squid-cache.org/
 # ----------------------------------------------------------
@@ -2274,6 +2274,15 @@ DOC_START
        enabled in which case performance will suffer badly anyway..).
 DOC_END
 
+NAME: netdb_filename
+TYPE: string
+DEFAULT: @DEFAULT_NETDB_FILE@
+LOC: Config.netdbFilename
+DOC_START
+       A filename where Squid stores it's netdb state between restarts.
+       To disable, enter "none".
+DOC_END
+
 COMMENT_START
  OPTIONS FOR FTP GATEWAYING
  -----------------------------------------------------------------------------
index e6051bdf32eb44ec3fa0276e06303d8c12e45dad..8106414fdf534ca0572b9349039f92e82d0ca8db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: net_db.cc,v 1.199 2007/12/14 23:11:47 amosjeffries Exp $
+ * $Id: net_db.cc,v 1.200 2007/12/27 14:55:47 hno Exp $
  *
  * DEBUG: section 38    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -463,28 +463,18 @@ sortPeerByRtt(const void *A, const void *B)
         return 0;
 }
 
-static void
-netdbPath(char *path)
-{
-    /* this is completely wrong. the netdb location should be memoised
-     * separately from the cache dirs, and also be settable in 
-     * squid.conf RBC 20041225
-     */
-    snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state",
-             dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[0].getRaw())->path);
-}
-
 static void
 netdbSaveState(void *foo)
 {
-    LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN);
+    if (strcmp(config.netdbFilename, "none") == 0)
+       return;
+
     Logfile *lf;
     netdbEntry *n;
     net_db_name *x;
 
     struct timeval start = current_time;
     int count = 0;
-    netdbPath(path);
     /*
      * This was nicer when we were using stdio, but thanks to
      * Solaris bugs, its a bad idea.  fopen can fail if more than
@@ -494,8 +484,8 @@ netdbSaveState(void *foo)
      * unlink() is here because there is currently no way to make
      * logfileOpen() use O_TRUNC.
      */
-    unlink(path);
-    lf = logfileOpen(path, 4096, 0);
+    unlink(Config.netdbFilename);
+    lf = logfileOpen(Config.netdbFilename, 4096, 0);
 
     if (NULL == lf) {
         debugs(50, 1, "netdbSaveState: " << path << ": " << xstrerror());
@@ -539,7 +529,9 @@ netdbSaveState(void *foo)
 static void
 netdbReloadState(void)
 {
-    LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN);
+    if (strcmp(config.netdbFilename, "none") == 0)
+       return;
+
     char *s;
     int fd;
     int l;
@@ -552,13 +544,12 @@ netdbReloadState(void)
     int count = 0;
 
     struct timeval start = current_time;
-    netdbPath(path);
     /*
      * This was nicer when we were using stdio, but thanks to
      * Solaris bugs, its a bad idea.  fopen can fail if more than
      * 256 FDs are open.
      */
-    fd = file_open(path, O_RDONLY | O_BINARY);
+    fd = file_open(Config.netdbFilename, O_RDONLY | O_BINARY);
 
     if (fd < 0)
         return;
index 272c3f0c328edfc8f3c15462e7536de03668b2f2..65ccdc6dfc35e6fb6e5f0b4cd55f07ccd6f7a951 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.570 2007/12/26 23:39:55 hno Exp $
+ * $Id: structs.h,v 1.571 2007/12/27 14:55:47 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -407,6 +407,7 @@ struct _SquidConfig
     size_t appendDomainLen;
     char *debugOptions;
     char *pidFilename;
+    char *netdbFilename;
     char *mimeTablePathname;
     char *etcHostsPath;
     char *visibleHostname;