You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by mt...@apache.org on 2010/05/29 16:37:35 UTC

svn commit: r949397 - in /trafficserver/traffic/trunk: iocore/cache/ iocore/hostdb/ proxy/ proxy/logging/ proxy/mgmt2/ proxy/mgmt2/cli/ proxy/mgmt2/cli2/ proxy/mgmt2/cop/ proxy/mgmt2/tools/

Author: mturk
Date: Sat May 29 14:37:34 2010
New Revision: 949397

URL: http://svn.apache.org/viewvc?rev=949397&view=rev
Log:
TS-381: Use access() instead stat() for checking resource availability

Modified:
    trafficserver/traffic/trunk/iocore/cache/Cache.cc
    trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
    trafficserver/traffic/trunk/proxy/DiagsConfig.cc
    trafficserver/traffic/trunk/proxy/Main.cc
    trafficserver/traffic/trunk/proxy/StatSystem.cc
    trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
    trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc
    trafficserver/traffic/trunk/proxy/mgmt2/FileManager.cc
    trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc
    trafficserver/traffic/trunk/proxy/mgmt2/Main.cc
    trafficserver/traffic/trunk/proxy/mgmt2/cli/CliUtils.cc
    trafficserver/traffic/trunk/proxy/mgmt2/cli/clientCLI.cc
    trafficserver/traffic/trunk/proxy/mgmt2/cli2/CliMgmtUtils.cc
    trafficserver/traffic/trunk/proxy/mgmt2/cop/TrafficCop.cc
    trafficserver/traffic/trunk/proxy/mgmt2/tools/ConfigAPI.cc

Modified: trafficserver/traffic/trunk/iocore/cache/Cache.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/cache/Cache.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/cache/Cache.cc (original)
+++ trafficserver/traffic/trunk/iocore/cache/Cache.cc Sat May 29 14:37:34 2010
@@ -2586,8 +2586,6 @@ register_cache_stats(RecRawStatBlock *rs
 void
 ink_cache_init(ModuleVersion v)
 {
-  struct stat s;
-  int ierr;
   ink_release_assert(!checkModuleVersion(v, CACHE_MODULE_VERSION));
 
   cache_rsb = RecAllocateRawStatBlock((int) cache_stat_count);
@@ -2651,15 +2649,16 @@ ink_cache_init(ModuleVersion v)
   IOCORE_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
-    ink_strncpy(cache_system_config_directory, system_config_directory, sizeof(cache_system_config_directory));
+    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 ((ierr = stat(cache_system_config_directory, &s)) < 0) {
-    ink_strncpy(cache_system_config_directory, Layout::get()->sysconfdir,
+  if (access(cache_system_config_directory, R_OK) == -1) {
+    ink_strlcpy(cache_system_config_directory, Layout::get()->sysconfdir,
                 sizeof(cache_system_config_directory));
-    if ((ierr = stat(cache_system_config_directory, &s)) < 0) {
-      fprintf(stderr,"unable to stat() config dir '%s': %d %d, %s\n",
-              cache_system_config_directory, ierr, errno, strerror(errno));
+    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);
     }
@@ -2726,8 +2725,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];
+    char p[PATH_NAME_MAX + 1];
     snprintf(p, sizeof(p), "%s/", cache_system_config_directory);
     IOCORE_ReadConfigString(p + strlen(p), "proxy.config.cache.storage_filename", PATH_NAME_MAX - strlen(p) - 1);
     if (p[strlen(p) - 1] == '/' || p[strlen(p) - 1] == '\\') {

Modified: trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc Sat May 29 14:37:34 2010
@@ -327,12 +327,11 @@ HostDBCache::start(int flags)
 
   Debug("hostdb", "Storage path is %s", storage_path);
 
-  struct stat s;
-  int err;
-  if ((err = stat(storage_path, &s)) < 0) {
+  // XXX: Should this be W_OK?
+  if (access(storage_path, R_OK) == -1) {
     ink_strncpy(storage_path, system_runtime_dir, sizeof(storage_path));
-    if ((err = stat(storage_path, &s)) < 0) {
-      Warning("Unable to stat() directory '%s': %d %d, %s", storage_path, err, errno, strerror(errno));
+    if (access(storage_path, R_OK) == -1) {
+      Warning("Unable to access() directory '%s': %d, %s", storage_path, errno, strerror(errno));
       Warning(" Please set 'proxy.config.hostdb.storage_path' or 'proxy.config.local_state_dir' ");
     }
   }

Modified: trafficserver/traffic/trunk/proxy/DiagsConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/DiagsConfig.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/DiagsConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/DiagsConfig.cc Sat May 29 14:37:34 2010
@@ -294,8 +294,6 @@ DiagsConfig::RegisterDiagConfig()
 DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records)
 {
   char diags_logpath[PATH_NAME_MAX + 1];
-  struct stat s;
-  int err;
   callbacks_established = false;
   diags_log_fp = (FILE *) NULL;
   diags = NULL;
@@ -315,13 +313,13 @@ DiagsConfig::DiagsConfig(char *bdt, char
   // open the diags log //
   ////////////////////////
 
-  if ((err = stat(system_log_dir, &s)) < 0) {
+  if (access(system_log_dir, R_OK) == -1) {
     REC_ReadConfigString(diags_logpath, "proxy.config.log2.logfile_dir", PATH_NAME_MAX);
     Layout::get()->relative(system_log_dir, PATH_NAME_MAX, diags_logpath);
 
-    if ((err = stat(system_log_dir, &s)) < 0) {
-      fprintf(stderr,"unable to stat() log dir'%s': %d %d, %s\n",
-              system_log_dir, err, errno, strerror(errno));
+    if (access(system_log_dir, R_OK) == -1) {
+      fprintf(stderr,"unable to access() log dir'%s': %d, %s\n",
+              system_log_dir, errno, strerror(errno));
       fprintf(stderr,"please set 'proxy.config.log2.logfile_dir'\n");
       _exit(1);
     }

Modified: trafficserver/traffic/trunk/proxy/Main.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/Main.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/Main.cc (original)
+++ trafficserver/traffic/trunk/proxy/Main.cc Sat May 29 14:37:34 2010
@@ -386,14 +386,13 @@ static void
 check_lockfile()
 {
   char *lockfile = NULL;
-  int err;
   pid_t holding_pid;
-  struct stat s;
+  int err;
 
 #ifndef _DLL_FOR_HNS
-  if ((err = stat(Layout::get()->runtimedir, &s)) < 0) {
-    fprintf(stderr,"unable to stat() dir'%s': %d %d, %s\n",
-            Layout::get()->runtimedir, err, errno, strerror(errno));
+  if (access(Layout::get()->runtimedir, R_OK | W_OK) == -1) {
+    fprintf(stderr,"unable to access() dir'%s': %d, %s\n",
+            Layout::get()->runtimedir, errno, strerror(errno));
     fprintf(stderr," please set correct path in env variable TS_ROOT \n");
     _exit(1);
   }
@@ -436,13 +435,11 @@ check_lockfile()
 static void
 init_dirs(void)
 {
-  struct stat s;
-  int err;
-  char buf[PATH_NAME_MAX+1];
+  char buf[PATH_NAME_MAX + 1];
 
-  ink_strncpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
-  ink_strncpy(system_runtime_dir, Layout::get()->runtimedir, PATH_NAME_MAX);
-  ink_strncpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);
+  ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
+  ink_strlcpy(system_runtime_dir, Layout::get()->runtimedir, PATH_NAME_MAX);
+  ink_strlcpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);
 
   /*
    * XXX: There is not much sense in the following code
@@ -450,34 +447,34 @@ init_dirs(void)
    * be checked BEFORE checking default foo directory.
    * Otherwise one cannot change the config dir to something else
    */
-  if ((err = stat(system_config_directory, &s)) < 0) {
+  if (access(system_config_directory, R_OK) == -1) {
     REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX);
     Layout::get()->relative(system_config_directory, PATH_NAME_MAX, buf);
-    if ((err = stat(system_config_directory, &s)) < 0) {
-      fprintf(stderr,"unable to stat() config dir '%s': %d %d, %s\n",
-              system_config_directory, err, errno, strerror(errno));
+    if (access(system_config_directory, R_OK) == -1) {
+      fprintf(stderr,"unable to access() config dir '%s': %d, %s\n",
+              system_config_directory, errno, strerror(errno));
       fprintf(stderr, "please set config path via 'proxy.config.config_dir' \n");
       _exit(1);
     }
   }
 
-  if ((err = stat(system_runtime_dir, &s)) < 0) {
+  if (access(system_runtime_dir, R_OK | W_OK) == -1) {
     REC_ReadConfigString(buf, "proxy.config.local_state_dir", PATH_NAME_MAX);
     Layout::get()->relative(system_runtime_dir, PATH_NAME_MAX, buf);
-    if ((err = stat(system_runtime_dir, &s)) < 0) {
-      fprintf(stderr,"unable to stat() local state dir '%s': %d %d, %s\n",
-              system_runtime_dir, err, errno, strerror(errno));
+    if (access(system_runtime_dir, R_OK | W_OK) == -1) {
+      fprintf(stderr,"unable to access() local state dir '%s': %d, %s\n",
+              system_runtime_dir, errno, strerror(errno));
       fprintf(stderr,"please set 'proxy.config.local_state_dir'\n");
       _exit(1);
     }
   }
 
-  if ((err = stat(system_log_dir, &s)) < 0) {
+  if (access(system_log_dir, W_OK) == -1) {
     REC_ReadConfigString(buf, "proxy.config.log2.logfile_dir", PATH_NAME_MAX);
     Layout::get()->relative(system_log_dir, PATH_NAME_MAX, buf);
-    if ((err = stat(system_log_dir, &s)) < 0) {
-      fprintf(stderr,"unable to stat() log dir'%s': %d %d, %s\n",
-              system_log_dir, err, errno, strerror(errno));
+    if (access(system_log_dir, W_OK) == -1) {
+      fprintf(stderr,"unable to access() log dir'%s':%d, %s\n",
+              system_log_dir, errno, strerror(errno));
       fprintf(stderr,"please set 'proxy.config.log2.logfile_dir'\n");
       _exit(1);
     }
@@ -492,8 +489,6 @@ static void
 initialize_process_manager()
 {
   ProcessRecords *precs;
-  struct stat s;
-  int err;
 
   mgmt_use_syslog();
 
@@ -502,11 +497,11 @@ initialize_process_manager()
     remote_management_flag = true;
   }
 
-  if ((err = stat(management_directory, &s)) < 0) {
+  if (access(management_directory, R_OK) == -1) {
     ink_strncpy(management_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
-    if ((err = stat(management_directory, &s)) < 0) {
-      fprintf(stderr,"unable to stat() management path '%s': %d %d, %s\n",
-                management_directory, err, errno, strerror(errno));
+    if (access(management_directory, R_OK) == -1) {
+      fprintf(stderr,"unable to access() management path '%s': %d, %s\n",
+                management_directory, errno, strerror(errno));
       fprintf(stderr,"please set management path via command line '-d <managment directory>'\n");
       _exit(1);
     }
@@ -620,9 +615,9 @@ clear_rn_cache()
   if (rn_cache_path) {
     if (*rn_cache_path != '\0') {
       // first check if the directory exists.
-      struct stat s;
-      if ((result = stat(rn_cache_path, &s)) < 0) {
-        Warning("unable to stat '%s': %d %d, %s", rn_cache_path, result, errno, strerror(errno));
+      if (access(rn_cache_path, F_OK) == -1) {
+        result = errno;
+        Warning("unable to access() '%s': %d, %s", rn_cache_path, errno, strerror(errno));
         Note("unable to clear RN Cache, CLEAR failed [%d]", result);
         return CMD_FAILED;
       }

Modified: trafficserver/traffic/trunk/proxy/StatSystem.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/StatSystem.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/StatSystem.cc (original)
+++ trafficserver/traffic/trunk/proxy/StatSystem.cc Sat May 29 14:37:34 2010
@@ -575,19 +575,17 @@ initialize_all_global_stats()
   int istat, i;
   char snap_file[PATH_NAME_MAX + 1];
   char local_state_dir[PATH_NAME_MAX + 1];
-  struct stat s;
-  int err;
 
   // Jira TS-21
   REC_ReadConfigString(local_state_dir, "proxy.config.local_state_dir", PATH_NAME_MAX);
   if (local_state_dir[0] != '/') {
     // Not an absolute path
-    ink_strncpy(local_state_dir, Layout::get()->runtimedir, sizeof(local_state_dir));
+    Layout::get()->relative(local_state_dir, sizeof(local_state_dir), local_state_dir);
   }
-  if ((err = stat(local_state_dir, &s)) < 0) {
-    ink_strncpy(local_state_dir,system_runtime_dir,sizeof(local_state_dir));
-    if ((err = stat(local_state_dir, &s)) < 0) {
-      Warning("Unable to stat() local state directory '%s': %d %d, %s", local_state_dir, err, errno, strerror(errno));
+  if (access(local_state_dir, R_OK | W_OK) == -1) {
+    ink_strlcpy(local_state_dir, system_runtime_dir, sizeof(local_state_dir));
+    if (access(local_state_dir, R_OK | W_OK) == -1) {
+      Warning("Unable to access() local state directory '%s': %d, %s", local_state_dir, errno, strerror(errno));
       Warning(" Please set 'proxy.config.local_state_dir' to allow statistics collection");
     }
   }

Modified: trafficserver/traffic/trunk/proxy/logging/LogConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogConfig.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogConfig.cc Sat May 29 14:37:34 2010
@@ -210,8 +210,6 @@ LogConfig::read_configuration_variables(
 {
   int val;
   char *ptr;
-  struct stat s;
-  int err;
 
   val = (int) LOG_ConfigReadInteger("proxy.config.log2.log_buffer_size");
   if (val > 0) {
@@ -288,13 +286,13 @@ LogConfig::read_configuration_variables(
     // Make it relative from Layout
     logfile_dir = Layout::get()->relative(ptr);
     xfree(ptr);
-    if ((err = stat(logfile_dir, &s)) < 0) {
+    if (access(logfile_dir, W_OK) == -1) {
       xfree(logfile_dir);
       logfile_dir = NULL;
-      if ((err = stat(system_log_dir, &s)) < 0) {
+      if (access(system_log_dir, W_OK) == -1) {
         // Try 'system_root_dir/var/log/trafficserver' directory
-        fprintf(stderr,"unable to stat() log dir'%s': %d %d, %s\n",
-                system_log_dir, err, errno, strerror(errno));
+        fprintf(stderr,"unable to access() log dir'%s': %d, %s\n",
+                system_log_dir, errno, strerror(errno));
         fprintf(stderr,"please set 'proxy.config.log2.logfile_dir'\n");
         _exit(1);
       }

Modified: trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogStandalone.cc Sat May 29 14:37:34 2010
@@ -126,8 +126,6 @@ static void
 initialize_process_manager()
 {
   ProcessRecords *precs;
-  struct stat s;
-  int err;
 
   mgmt_use_syslog();
 
@@ -138,9 +136,9 @@ initialize_process_manager()
 
   if (management_directory[0] == '\0') {
     ink_strncpy(management_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
-    if ((err = stat(management_directory, &s)) < 0) {
-      fprintf(stderr,"unable to stat() management path '%s': %d %d, %s\n",
-              management_directory, err, errno, strerror(errno));
+    if (access(management_directory, R_OK) == -1) {
+      fprintf(stderr,"unable to access() management path '%s': %d, %s\n",
+              management_directory, errno, strerror(errno));
       fprintf(stderr,"please set management path via command line '-d <managment directory>'\n");
       _exit(1);
     }
@@ -210,10 +208,9 @@ check_lockfile(const char *config_dir, c
   pid_t holding_pid;
   char *lockfile = NULL;
 
-  struct stat s;
-  if ((err = stat(Layout::get()->runtimedir, &s)) < 0) {
-    fprintf(stderr,"unable to stat() dir'%s': %d %d, %s\n",
-            Layout::get()->runtimedir, err, errno, strerror(errno));
+  if (access(Layout::get()->runtimedir, R_OK | W_OK) == -1) {
+    fprintf(stderr,"unable to access() dir'%s': %d, %s\n",
+            Layout::get()->runtimedir, errno, strerror(errno));
     fprintf(stderr," please set correct path in env variable TS_ROOT \n");
     _exit(1);
   }
@@ -319,19 +316,16 @@ init_log_standalone_basic(const char *pg
 int
 get_ts_directory(char *ts_path, size_t ts_path_len)
 {
-  struct stat s;
-  int err;
 
   // TODO: This should probably be logdir?
   ink_strncpy(ts_path, Layout::get()->prefix, ts_path_len);
 
-  if ((err = stat(ts_path, &s)) < 0) {
-    fprintf(stderr,"unable to stat() TS PATH '%s': %d %d, %s\n",
-              ts_path, err, errno, strerror(errno));
+  if (access(ts_path, R_OK) == -1) {
+    fprintf(stderr,"unable to access() TS ROOT '%s': %d, %s\n",
+              ts_path, errno, strerror(errno));
     fprintf(stderr," Please set correct path in env variable TS_ROOT \n");
     return -1;
   }
 
   return 0;
 }
-

Modified: trafficserver/traffic/trunk/proxy/mgmt2/FileManager.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/FileManager.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/FileManager.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/FileManager.cc Sat May 29 14:37:34 2010
@@ -22,6 +22,7 @@
  */
 
 #include "inktomi++.h"
+#include "I_Layout.h"
 #include "FileManager.h"
 #include "Main.h"
 #include "Rollback.h"
@@ -65,10 +66,8 @@ const char *SnapshotStrings[] = { "Reque
 
 FileManager::FileManager()
 {
-  char configTmp[PATH_NAME_MAX];
+  char configTmp[PATH_NAME_MAX + 1];
   int pathLen;
-  struct stat statBuf;
-  int err;
 
   bindings = ink_hash_table_create(InkHashTableKeyType_String);
 
@@ -81,11 +80,15 @@ FileManager::FileManager()
     mgmt_fatal(stderr,
                "[FileManager::FileManager] Unable to find configuration directory from proxy.config.config_dir\n");
   }
-  if ((err = stat(configTmp, &statBuf)) < 0) {
+  if (configTmp[0] != '/') {
+    // Make it TS_ROOT relative
+    Layout::get()->relative(configTmp, sizeof(configTmp), configTmp);
+  }
+  if (access(configTmp, R_OK) == -1) {
     ink_strncpy(configTmp, system_config_directory,sizeof(configTmp));
-    if ((err = stat(configTmp, &statBuf)) < 0) {
-        mgmt_elog("[FileManager::FileManager] unable to stat() directory '%s': %d %d, %s\n",
-                mgmt_path, err, errno, strerror(errno));
+    if (access(configTmp, R_OK) == -1) {
+        mgmt_elog("[FileManager::FileManager] unable to access() directory '%s': %d, %s\n",
+                mgmt_path, errno, strerror(errno));
         mgmt_elog("[FileManager::FileManager] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
         _exit(1);
     }
@@ -102,7 +105,7 @@ FileManager::FileManager()
 
   // Check to see if the directory already exists, if not create
   //  it
-  if (stat(snapshotDir, &statBuf) < 0) {
+  if (access(snapshotDir, F_OK) == -1) {
 #ifndef _WIN32
     if (mkdir(snapshotDir, DIR_MODE) < 0) {
 #else
@@ -383,7 +386,6 @@ FileManager::restoreSnap(const char *sna
   SnapResult result = SNAP_OK;
   char *snapPath;
   char *filePath = NULL;
-  struct stat fileInfo;
   textBuffer storage(2048);
 
   snapPath = newPathString(snapDir, snapName);
@@ -392,7 +394,7 @@ FileManager::restoreSnap(const char *sna
 
 
 
-  if (stat(snapPath, &fileInfo) < 0) {
+  if (access(snapPath, F_OK) == -1) {
     delete[]snapPath;
     ink_mutex_release(&accessLock);
     return SNAP_NOT_FOUND;

Modified: trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc Sat May 29 14:37:34 2010
@@ -143,7 +143,7 @@ LocalManager::rollLogFiles()
   return;
 }
 
-char snap_filename[FILE_NAME_MAX+1] = "stats.snap";
+char snap_filename[PATH_NAME_MAX + 1] = "stats.snap";
 
 void
 LocalManager::clearStats()
@@ -151,17 +151,15 @@ LocalManager::clearStats()
   char *statsPath;
   char conf[PATH_NAME_MAX + 1];
   char local_state_dir[PATH_NAME_MAX + 1];
-  struct stat s;
-  int err;
 
   REC_ReadConfigString(conf, "proxy.config.local_state_dir", PATH_NAME_MAX);
   Layout::get()->relative(local_state_dir, sizeof(local_state_dir), conf);
-  if ((err = stat(local_state_dir, &s)) < 0) {
-    Warning("Unable to stat() local state directory '%s': %d %d, %s", local_state_dir, err, errno, strerror(errno));
+  if (access(local_state_dir, R_OK | W_OK) == -1) {
+    Warning("Unable to access() local state directory '%s': %d, %s", local_state_dir, errno, strerror(errno));
     Warning(" Please set 'proxy.config.local_state_dir' to allow statistics collection");
   }
   REC_ReadConfigString(conf, "proxy.config.stats.snap_file", PATH_NAME_MAX);
-  snprintf(snap_filename, sizeof(snap_filename), "%s/%s", local_state_dir, conf);
+  ink_filepath_make(snap_filename, sizeof(snap_filename), local_state_dir, conf);
 
   // Clear our records and then send the signal.  There is a race condition
   //  here where our stats could get re-updated from the proxy
@@ -240,8 +238,6 @@ LocalManager::LocalManager(char *mpath, 
 BaseManager(), run_proxy(proxy_on), record_data(rd)
 {
   bool found;
-  struct stat s;
-  int err;
 #ifdef MGMT_USE_SYSLOG
   syslog_facility = 0;
 #endif
@@ -364,14 +360,17 @@ BaseManager(), run_proxy(proxy_on), reco
     proxy_server_incoming_ip_to_bind = htonl(INADDR_ANY);
   }
   config_path = REC_readString("proxy.config.config_dir", &found);
-  if ((err = stat(config_path, &s)) < 0) {
-    xfree(config_path);
+  char *absolute_config_path = Layout::get()->relative(config_path);
+  xfree(config_path);
+  if (access(absolute_config_path, R_OK) == -1) {
     config_path = xstrdup(system_config_directory);
-    if ((err = stat(config_path, &s)) < 0) {
-        mgmt_elog("[LocalManager::LocalManager] unable to stat() directory '%s': %d %d, %s\n",
-                config_path, err, errno, strerror(errno));
+    if (access(config_path, R_OK) == -1) {
+        mgmt_elog("[LocalManager::LocalManager] unable to access() directory '%s': %d, %s\n",
+                config_path, errno, strerror(errno));
         mgmt_fatal("[LocalManager::LocalManager] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
     }
+  } else {
+    config_path = absolute_config_path;
   }
 
   bin_path = REC_readString("proxy.config.bin_path", &found);
@@ -388,14 +387,14 @@ BaseManager(), run_proxy(proxy_on), reco
   // Calculate proxy_binary from the absolute bin_path
   absolute_proxy_binary = Layout::relative_to(absolute_bin_path, proxy_binary);
 
-  if ((err = stat(absolute_proxy_binary, &s)) < 0) {
+  if (access(absolute_proxy_binary, R_OK | X_OK) == -1) {
     // Try 'Layout::bindir' directory
     xfree(absolute_proxy_binary);
     absolute_proxy_binary = Layout::relative_to(Layout::get()->bindir, proxy_binary);
     // coverity[fs_check_call]
-    if ((err = stat(absolute_proxy_binary, &s)) < 0) {
-        mgmt_elog("[LocalManager::LocalManager] Unable to find '%s': %d %d, %s\n",
-                absolute_proxy_binary, err, errno, strerror(errno));
+    if (access(absolute_proxy_binary, R_OK | X_OK) == -1) {
+        mgmt_elog("[LocalManager::LocalManager] Unable to access() '%s': %d, %s\n",
+                absolute_proxy_binary, errno, strerror(errno));
         mgmt_fatal("[LocalManager::LocalManager] please set bin path 'proxy.config.bin_path' \n");
     }
   }
@@ -1093,8 +1092,7 @@ LocalManager::convert_filters()
     snprintf(absolute_convert_binary, absolute_convert_binary_size, "%s/%s", bin_path, convert_bin);
 
     // check that the binary exists
-    struct stat fileInfo;
-    if (stat(absolute_convert_binary, &fileInfo) < 0) {
+    if (access(absolute_convert_binary, R_OK | X_OK) == -1) {
       mgmt_elog(stderr,
                 "[LocalManager::startProxy] "
                 "%s cannot be executed because it does not exist", absolute_convert_binary);

Modified: trafficserver/traffic/trunk/proxy/mgmt2/Main.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/Main.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/Main.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/Main.cc Sat May 29 14:37:34 2010
@@ -313,49 +313,47 @@ setup_coredump()
 static void
 init_dirs(bool use_librecords = true)
 {
-  struct stat s;
-  int err;
-  char buf[PATH_NAME_MAX+1];
+  char buf[PATH_NAME_MAX + 1];
 
   ink_strncpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
   ink_strncpy(system_runtime_dir, Layout::get()->runtimedir, PATH_NAME_MAX);
   ink_strncpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);
 
-  if ((err = stat(system_config_directory, &s)) < 0) {
+  if (access(system_config_directory, R_OK) == -1) {
     if (use_librecords) {
       REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX);
       Layout::get()->relative(system_config_directory, PATH_NAME_MAX, buf);
     }
-    if ((err = stat(system_config_directory, &s)) < 0) {
-      mgmt_elog("unable to stat() config dir '%s': %d %d, %s\n",
-              system_config_directory, err, errno, strerror(errno));
+    if (access(system_config_directory, R_OK) == -1) {
+      mgmt_elog("unable to access() config dir '%s': %d, %s\n",
+              system_config_directory, errno, strerror(errno));
       mgmt_elog("please set config path via 'proxy.config.config_dir' \n");
       _exit(1);
     }
   }
   strcpy(mgmt_path, system_config_directory);
 
-  if ((err = stat(system_runtime_dir, &s)) < 0) {
+  if (access(system_runtime_dir, W_OK) == -1) {
     if (use_librecords) {
       REC_ReadConfigString(buf, "proxy.config.local_state_dir", PATH_NAME_MAX);
       Layout::get()->relative(system_runtime_dir, PATH_NAME_MAX, buf);
     }
-    if ((err = stat(system_runtime_dir, &s)) < 0) {
-      mgmt_elog("unable to stat() local state dir '%s': %d %d, %s\n",
-              system_runtime_dir, err, errno, strerror(errno));
+    if (access(system_runtime_dir, R_OK) == -1) {
+      mgmt_elog("unable to access() local state dir '%s': %d, %s\n",
+              system_runtime_dir, errno, strerror(errno));
       mgmt_elog("please set 'proxy.config.local_state_dir'\n");
       _exit(1);
     }
   }
 
-  if ((err = stat(system_log_dir, &s)) < 0) {
+  if (access(system_log_dir, W_OK) == -1) {
     if (use_librecords) {
       REC_ReadConfigString(buf, "proxy.config.log2.logfile_dir", PATH_NAME_MAX);
       Layout::get()->relative(system_log_dir, PATH_NAME_MAX, buf);
     }
-    if ((err = stat(system_log_dir, &s)) < 0) {
-      mgmt_elog("unable to stat() log dir'%s': %d %d, %s\n",
-              system_log_dir, err, errno, strerror(errno));
+    if (access(system_log_dir, W_OK) == -1) {
+      mgmt_elog("unable to access() log dir'%s': %d, %s\n",
+              system_log_dir, errno, strerror(errno));
       mgmt_elog("please set 'proxy.config.log2.logfile_dir'\n");
       _exit(1);
     }
@@ -1415,7 +1413,7 @@ fileUpdated(char *fname)
     @endcode
     but that had no effect even though the call reported succes.
     Only explicit capability manipulation was effective.
-    
+
     It does not appear to be necessary to set the capabilities on the
     executable if originally run as root. That may be needed if
     started as a user without that capability.

Modified: trafficserver/traffic/trunk/proxy/mgmt2/cli/CliUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cli/CliUtils.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cli/CliUtils.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cli/CliUtils.cc Sat May 29 14:37:34 2010
@@ -304,14 +304,12 @@ DEFAULT_TS_DIRECTORY_FILE
 int
 GetTSDirectory(char *ts_path, size_t ts_path_len)
 {
-  struct stat s;
-  int err;
 
   ink_strncpy(ts_path, Layout::get()->bindir, ts_path_len);
 
-  if ((err = stat(ts_path, &s)) < 0) {
-    printf("unable to stat() TS PATH '%s': %d %d, %s\n",
-              ts_path, err, errno, strerror(errno));
+  if (access(ts_path, R_OK) == -1) {
+    printf("unable to stat() '%s': %d, %s\n",
+              ts_path, errno, strerror(errno));
     printf(" Please set correct path in env variable TS_ROOT \n");
     return -1;
   }

Modified: trafficserver/traffic/trunk/proxy/mgmt2/cli/clientCLI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cli/clientCLI.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cli/clientCLI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cli/clientCLI.cc Sat May 29 14:37:34 2010
@@ -75,13 +75,11 @@ clientCLI::~clientCLI(void)
 int
 clientCLI::GetTSDirectory(char *ts_path, size_t ts_path_len)
 {
-  struct stat s;
-  int err;
 
   ink_strncpy(ts_path, Layout::get()->bindir, ts_path_len);
-  if ((err = stat(ts_path, &s)) < 0) {
-    fprintf(stderr,"unable to stat() TS PATH '%s': %d %d, %s\n",
-              ts_path, err, errno, strerror(errno));
+  if (access(ts_path, R_OK) == -1) {
+    fprintf(stderr,"unable to access() '%s': %d, %s\n",
+              ts_path, errno, strerror(errno));
     fprintf(stderr," Please set correct path in env variable TS_ROOT \n");
     return -1;
   }

Modified: trafficserver/traffic/trunk/proxy/mgmt2/cli2/CliMgmtUtils.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cli2/CliMgmtUtils.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cli2/CliMgmtUtils.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cli2/CliMgmtUtils.cc Sat May 29 14:37:34 2010
@@ -553,13 +553,11 @@ cliCheckIfEnabled(const char *command)
 int
 GetTSDirectory(char *ts_path, size_t ts_path_len)
 {
-  int err;
-  struct stat s;
 
   ink_strncpy(ts_path, Layout::get()->bindir, ts_path_len);
-  if ((err = stat(ts_path, &s)) < 0) {
-    Cli_Error("unable to stat() TS PATH '%s': %d %d, %s\n",
-              ts_path, err, errno, strerror(errno));
+  if (access(ts_path, R_OK) == -1) {
+    Cli_Error("unable to access() '%s': %d, %s\n",
+              ts_path, errno, strerror(errno));
     Cli_Error(" Please set correct path in env variable TS_ROOT \n");
     return -1;
   }

Modified: trafficserver/traffic/trunk/proxy/mgmt2/cop/TrafficCop.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cop/TrafficCop.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cop/TrafficCop.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cop/TrafficCop.cc Sat May 29 14:37:34 2010
@@ -652,18 +652,20 @@ read_config()
   read_config_string("proxy.config.manager_binary", manager_binary, sizeof(manager_binary));
   read_config_string("proxy.config.proxy_binary", server_binary, sizeof(server_binary));
   read_config_string("proxy.config.bin_path", bin_path, sizeof(bin_path));
-  if (stat(bin_path, &stat_buf) < 0) {
-    ink_strncpy(Layout::get()->bindir, bin_path, sizeof(bin_path) - 1);
-    if (stat(log_dir, &stat_buf) < 0) {
-      cop_log(COP_FATAL, "could not stat \"%s\"\n", bin_path);
+  Layout::get()->relative(bin_path, sizeof(bin_path), bin_path);
+  if (access(bin_path, R_OK) == -1) {
+    ink_strlcpy(bin_path, Layout::get()->bindir, sizeof(bin_path));
+    if (access(bin_path, R_OK) == -1) {
+      cop_log(COP_FATAL, "could not access() \"%s\"\n", bin_path);
       cop_log(COP_FATAL, "please set 'proxy.config.bin_path' \n");
     }
   }
   read_config_string("proxy.config.log2.logfile_dir", log_dir, sizeof(log_dir));
-  if (stat(log_dir, &stat_buf) < 0) {
-    ink_strncpy(Layout::get()->logdir, log_dir, sizeof(log_dir) - 1);
-    if (stat(log_dir, &stat_buf) < 0) {
-      cop_log(COP_FATAL, "could not stat \"%s\"\n", log_dir);
+  Layout::get()->relative(log_dir, sizeof(log_dir), log_dir);
+  if (access(log_dir, W_OK) == -1) {
+    ink_strlcpy(log_dir, Layout::get()->logdir, sizeof(log_dir));
+    if (access(log_dir, W_OK) == -1) {
+      cop_log(COP_FATAL, "could not access() \"%s\"\n", log_dir);
       cop_log(COP_FATAL, "please set 'proxy.config.log2.logfile_dir' \n");
     }
   }
@@ -703,7 +705,6 @@ read_config()
 static void
 spawn_manager()
 {
-  struct stat info;
   char prog[PATH_MAX];
   char *options[OPTIONS_MAX];
   char *last;
@@ -738,8 +739,8 @@ spawn_manager()
   }
 
   Layout::relative_to(prog, sizeof(prog), bin_path, manager_binary);
-  if (stat(prog, &info) < 0) {
-    cop_log(COP_FATAL, "unable to find manager binary \"%s\" [%d '%s']\n", prog, errno, strerror(errno));
+  if (access(prog, R_OK | X_OK) == -1) {
+    cop_log(COP_FATAL, "unable to access() manager binary \"%s\" [%d '%s']\n", prog, errno, strerror(errno));
     exit(1);
   }
 

Modified: trafficserver/traffic/trunk/proxy/mgmt2/tools/ConfigAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/tools/ConfigAPI.cc?rev=949397&r1=949396&r2=949397&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/tools/ConfigAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/tools/ConfigAPI.cc Sat May 29 14:37:34 2010
@@ -1411,12 +1411,11 @@ Config_FloppyNetRestore()
   //char *gui_passwd, *e_gui_passwd;
   //INKActionNeedT action_need, top_action_req = INK_ACTION_UNDEFINED;
   int status = 0;
-  struct stat buf;
 
-  Layout::relative_to(net_floppy_config, PATH_NAME_MAX,
-                      Layout::get()->bindir, "net_floppy_config");
+  ink_filepath_make(net_floppy_config, PATH_NAME_MAX,
+                    Layout::get()->bindir, "net_floppy_config");
 
-  if (stat(net_floppy_config, &buf) < 0) {
+  if (access(net_floppy_config, R_OK | X_OK) == -1) {
     DPRINTF(("Config_FloppyNetRestore: net_floppy_config does not exist - abort\n"));
     return 1;
   }