TS-2401: Remove cache_system_config_directory

Remove the global cache_system_config_directory array. It was only
really being used for an error message. The only real place where
it could have been use already used Layout::sysconfdir.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b6288c44
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b6288c44
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b6288c44

Branch: refs/heads/5.0.x
Commit: b6288c446f65d48f047af8b57991d41203e4f2c0
Parents: 67306a7
Author: James Peach <jpe...@apache.org>
Authored: Mon Dec 2 15:19:56 2013 -0800
Committer: James Peach <jpe...@apache.org>
Committed: Thu Dec 5 20:33:49 2013 -0800

----------------------------------------------------------------------
 iocore/cache/Cache.cc            | 33 +++------------------------
 iocore/cache/CacheHosting.cc     | 42 ++++++++++++-----------------------
 iocore/cache/P_CacheHosting.h    |  5 ++---
 iocore/cache/P_CacheInternal.h   |  1 -
 iocore/cache/Store.cc            | 12 ++--------
 iocore/cluster/ClusterMachine.cc | 12 ++++------
 lib/records/I_RecCore.h          |  2 +-
 lib/records/RecCore.cc           |  6 ++++-
 8 files changed, 31 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index bf80228..39688a7 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -77,7 +77,6 @@ int cache_config_agg_write_backlog = AGG_SIZE * 2;
 int cache_config_enable_checksum = 0;
 int cache_config_alt_rewrite_max_size = 4096;
 int cache_config_read_while_writer = 0;
-char cache_system_config_directory[PATH_NAME_MAX + 1];
 int cache_config_mutex_retry_delay = 2;
 #ifdef HTTP_CACHE
 static int enable_cache_empty_http_doc = 0;
@@ -3358,26 +3357,6 @@ ink_cache_init(ModuleVersion v)
   REC_EstablishStaticConfigInt32(cache_config_mutex_retry_delay, 
"proxy.config.cache.mutex_retry_delay");
   Debug("cache_init", "proxy.config.cache.mutex_retry_delay = %dms", 
cache_config_mutex_retry_delay);
 
-  // This is just here to make sure IOCORE "standalone" works, it's usually 
configured in RecordsConfig.cc
-  RecRegisterConfigString(RECT_CONFIG, "proxy.config.config_dir", 
TS_BUILD_SYSCONFDIR, RECU_DYNAMIC, RECC_NULL, NULL);
-  REC_ReadConfigString(cache_system_config_directory, 
"proxy.config.config_dir", PATH_NAME_MAX);
-  if (cache_system_config_directory[0] != '/') {
-    // Not an absolute path so use system one
-    Layout::get()->relative(cache_system_config_directory, 
sizeof(cache_system_config_directory), cache_system_config_directory);
-  }
-  Debug("cache_init", "proxy.config.config_dir = \"%s\"", 
cache_system_config_directory);
-  if (access(cache_system_config_directory, R_OK) == -1) {
-    ink_strlcpy(cache_system_config_directory, Layout::get()->sysconfdir,
-                sizeof(cache_system_config_directory));
-    Debug("cache_init", "proxy.config.config_dir = \"%s\"", 
cache_system_config_directory);
-    if (access(cache_system_config_directory, R_OK) == -1) {
-      fprintf(stderr,"unable to access() config dir '%s': %d, %s\n",
-              cache_system_config_directory, errno, strerror(errno));
-      fprintf(stderr, "please set config path via 'proxy.config.config_dir' 
\n");
-      _exit(1);
-    }
-  }
-
   REC_EstablishStaticConfigInt32(cache_config_hit_evacuate_percent, 
"proxy.config.cache.hit_evacuate_percent");
   Debug("cache_init", "proxy.config.cache.hit_evacuate_percent = %d", 
cache_config_hit_evacuate_percent);
 
@@ -3423,16 +3402,10 @@ ink_cache_init(ModuleVersion v)
     printf("%s  failed\n", err);
     exit(1);
   }
-  // XXX: The read for proxy.config.cache.storage_filename is unused!
-  //
+
   if (theCacheStore.n_disks == 0) {
-    char p[PATH_NAME_MAX + 1];
-    snprintf(p, sizeof(p), "%s/", cache_system_config_directory);
-    REC_ReadConfigString(p + strlen(p), "proxy.config.cache.storage_filename", 
PATH_NAME_MAX - strlen(p) - 1);
-    if (p[strlen(p) - 1] == '/' || p[strlen(p) - 1] == '\\') {
-      ink_strlcat(p, "storage.config", sizeof(p));
-    }
-    Warning("no cache disks specified in %s: cache disabled\n", p);
+    xptr<char> 
path(RecConfigReadConfigPath("proxy.config.cache.storage_filename", 
"storage.config"));
+    Warning("no cache disks specified in %s: cache disabled\n", (const char 
*)path);
     //exit(1);
   }
 #if TS_USE_INTERIM_CACHE == 1

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cache/CacheHosting.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index 93ba8e6..e3c07e3 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -192,7 +192,7 @@ CacheHostMatcher::NewEntry(matcher_line * line_info)
 
 CacheHostTable::CacheHostTable(Cache * c, CacheType typ)
 {
-
+  xptr<char> config_path;
 
   config_tags = &CacheHosting_tags;
   ink_assert(config_tags != NULL);
@@ -200,16 +200,12 @@ CacheHostTable::CacheHostTable(Cache * c, CacheType typ)
   type = typ;
   cache = c;
   matcher_name = "[CacheHosting]";;
-  config_file_path[0] = '\0';
-  char *config_file = NULL;
-  REC_ReadConfigStringAlloc(config_file, 
"proxy.config.cache.hosting_filename");
-  ink_release_assert(config_file != NULL);
-  Layout::relative_to(config_file_path, sizeof(config_file_path),
-                      cache_system_config_directory, config_file);
-  ats_free(config_file);
   hostMatch = NULL;
 
-  m_numEntries = this->BuildTable();
+  config_path = RecConfigReadConfigPath("proxy.config.cache.hosting_filename");
+  ink_release_assert(config_path);
+
+  m_numEntries = this->BuildTable(config_path);
 }
 
 CacheHostTable::~CacheHostTable()
@@ -263,7 +259,7 @@ int fstat_wrapper(int fd, struct stat *s);
 //      from it
 //
 int
-CacheHostTable::BuildTableFromString(char *file_buf)
+CacheHostTable::BuildTableFromString(const char * config_file_path, char 
*file_buf)
 {
   // Table build locals
   Tokenizer bufTok("\n");
@@ -417,10 +413,8 @@ CacheHostTable::BuildTableFromString(char *file_buf)
 }
 
 int
-CacheHostTable::BuildTable()
+CacheHostTable::BuildTable(const char * config_file_path)
 {
-
-  // File I/O Locals
   char *file_buf;
   int ret;
 
@@ -432,7 +426,7 @@ CacheHostTable::BuildTable()
     return 0;
   }
 
-  ret = BuildTableFromString(file_buf);
+  ret = BuildTableFromString(config_file_path, file_buf);
   ats_free(file_buf);
   return ret;
 }
@@ -631,27 +625,19 @@ CacheHostRecord::Print()
 void
 ConfigVolumes::read_config_file()
 {
-
-// File I/O Locals
+  xptr<char> config_path;
   char *file_buf;
-  char config_file_path[PATH_NAME_MAX];
-  char *config_file = NULL;
-  config_file_path[0] = '\0';
-
-  REC_ReadConfigStringAlloc(config_file, "proxy.config.cache.volume_filename");
-  ink_release_assert(config_file != NULL);
-  Layout::relative_to(config_file_path, sizeof(config_file_path),
-                      cache_system_config_directory, config_file);
-  ats_free(config_file);
 
-  file_buf = readIntoBuffer(config_file_path, "[CacheVolition]", NULL);
+  config_path = RecConfigReadConfigPath("proxy.config.cache.volume_filename");
+  ink_release_assert(config_path);
 
+  file_buf = readIntoBuffer(config_path, "[CacheVolition]", NULL);
   if (file_buf == NULL) {
-    Warning("Cannot read the config file: %s", config_file_path);
+    Warning("Cannot read the config file: %s", (const char *)config_path);
     return;
   }
 
-  BuildListFromString(config_file_path, file_buf);
+  BuildListFromString(config_path, file_buf);
   ats_free(file_buf);
   return;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cache/P_CacheHosting.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheHosting.h b/iocore/cache/P_CacheHosting.h
index cd3ca2b..dc7008a 100644
--- a/iocore/cache/P_CacheHosting.h
+++ b/iocore/cache/P_CacheHosting.h
@@ -105,8 +105,8 @@ public:
   //  object is
   CacheHostTable(Cache *c, CacheType typ);
    ~CacheHostTable();
-  int BuildTable();
-  int BuildTableFromString(char *str);
+  int BuildTable(const char * config_file_path);
+  int BuildTableFromString(const char * config_file_path, char *str);
   void Match(char *rdata, int rlen, CacheHostResult *result);
   void Print();
 
@@ -128,7 +128,6 @@ public:
 private:
   CacheHostMatcher *hostMatch;
   const matcher_tags *config_tags;
-  char config_file_path[PATH_NAME_MAX];
   const char *matcher_name;     // Used for Debug/Warning/Error messages
 };
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cache/P_CacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 20b89b3..f9a5845 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -219,7 +219,6 @@ extern int cache_config_agg_write_backlog;
 extern int cache_config_enable_checksum;
 extern int cache_config_alt_rewrite_max_size;
 extern int cache_config_read_while_writer;
-extern char cache_system_config_directory[PATH_NAME_MAX + 1];
 extern int cache_clustering_enabled;
 extern int cache_config_agg_write_backlog;
 extern int cache_config_ram_cache_compress;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cache/Store.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index bd13bfd..2e79958 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -296,17 +296,9 @@ Store::read_config(int fd)
   // Get pathname if not checking file
 
   if (fd < 0) {
-    char storage_path[PATH_NAME_MAX + 1];
-    char storage_file[PATH_NAME_MAX + 1];
-    // XXX: cache_system_config_directory is initialized
-    //      inside ink_cache_init() which is called AFTER
-    //      initialize_store().
-    //
-    // ink_strlcpy(p, cache_system_config_directory, sizeof(p));
-    REC_ReadConfigString(storage_file, "proxy.config.cache.storage_filename", 
PATH_NAME_MAX);
-    Layout::relative_to(storage_path, PATH_NAME_MAX, 
Layout::get()->sysconfdir, storage_file);
-    Debug("cache_init", "Store::read_config, fd = -1, \"%s\"", storage_path);
+    xptr<char> 
storage_path(RecConfigReadConfigPath("proxy.config.cache.storage_filename", 
"storage.config"));
 
+    Debug("cache_init", "Store::read_config, fd = -1, \"%s\"", (const char 
*)storage_path);
     fd =::open(storage_path, O_RDONLY);
     if (fd < 0) {
       err = "error on open";

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/iocore/cluster/ClusterMachine.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterMachine.cc b/iocore/cluster/ClusterMachine.cc
index 00e99e6..408ae8a 100644
--- a/iocore/cluster/ClusterMachine.cc
+++ b/iocore/cluster/ClusterMachine.cc
@@ -29,7 +29,7 @@
 #include "ink_config.h"
 #include <unistd.h>
 #include "P_Cluster.h"
-extern char cache_system_config_directory[PATH_NAME_MAX + 1];
+#include "I_Layout.h"
 extern int num_of_cluster_threads;
 
 MachineList *machines_config = NULL;
@@ -214,13 +214,9 @@ read_MachineList(char *filename, int afd)
   int n = -1, i = 0, ln = 0;
   MachineList *l = NULL;
   ink_assert(filename || (afd != -1));
-  char p[PATH_NAME_MAX];
-  if (filename) {
-    ink_strlcpy(p, cache_system_config_directory, sizeof(p));
-    ink_strlcat(p, "/", sizeof(p));
-    ink_strlcat(p, filename, sizeof(p));
-  }
-  int fd = ((afd != -1) ? afd : open(p, O_RDONLY));
+  xptr<char> path(Layout::get()->relative_to(Layout::get()->sysconfdir, 
filename));
+
+  int fd = ((afd != -1) ? afd : open(path, O_RDONLY));
   if (fd >= 0) {
     while (ink_file_fd_readline(fd, sizeof(line) - 1, line) > 0) {
       ln++;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/lib/records/I_RecCore.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h
index 44b0922..8462752 100644
--- a/lib/records/I_RecCore.h
+++ b/lib/records/I_RecCore.h
@@ -56,7 +56,7 @@ char * RecConfigReadSnapshotDir();
 // Return a copy of a configuration file that is relative to sysconfdir. The 
relative path to the configuration
 // file is specified in the configuration variable named by "file_variable". 
If the configuration variable has no
 // value, NULL is returned. The caller MUST release the result with ats_free().
-char * RecConfigReadConfigPath(const char * file_variable);
+char * RecConfigReadConfigPath(const char * file_variable, const char * 
default_value = NULL);
 
 // Test whether the named configuration value is overridden by an environment 
variable. Return either
 // the overridden value, or the original value. Caller MUST NOT free the 
result.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b6288c44/lib/records/RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc
index d76cb90..6c17cc9 100644
--- a/lib/records/RecCore.cc
+++ b/lib/records/RecCore.cc
@@ -1091,7 +1091,7 @@ RecConfigReadSnapshotDir()
 // RecConfigReadConfigPath
 //-------------------------------------------------------------------------
 char *
-RecConfigReadConfigPath(const char * file_variable)
+RecConfigReadConfigPath(const char * file_variable, const char * default_value)
 {
   char buf[PATH_NAME_MAX + 1];
 
@@ -1101,6 +1101,10 @@ RecConfigReadConfigPath(const char * file_variable)
     return Layout::get()->relative_to(Layout::get()->sysconfdir, buf);
   }
 
+  if (default_value) {
+    return Layout::get()->relative_to(Layout::get()->sysconfdir, 
default_value);
+  }
+
   return NULL;
 }
 

Reply via email to