You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2013/07/23 01:56:48 UTC

[08/11] git commit: TS-2041: rename traffic_cop config functions for better consistency

TS-2041: rename traffic_cop config functions for better consistency


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

Branch: refs/heads/master
Commit: 012c791eecb611de6e2728cd24607f172056636e
Parents: 7aa433e
Author: James Peach <jp...@apache.org>
Authored: Fri Jul 19 13:42:37 2013 -0700
Committer: James Peach <jp...@apache.org>
Committed: Mon Jul 22 16:52:03 2013 -0700

----------------------------------------------------------------------
 cop/TrafficCop.cc | 127 ++++++++++++++++++++++++-------------------------
 1 file changed, 63 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/012c791e/cop/TrafficCop.cc
----------------------------------------------------------------------
diff --git a/cop/TrafficCop.cc b/cop/TrafficCop.cc
index 5b72080..d1368fa 100644
--- a/cop/TrafficCop.cc
+++ b/cop/TrafficCop.cc
@@ -487,13 +487,13 @@ transient_error(int error, int wait_ms)
 }
 
 static void
-register_config_variable(RecT rec_type, RecDataT data_type, const char * name, const char * value)
+config_register_variable(RecT rec_type, RecDataT data_type, const char * name, const char * value)
 {
   configTable.insert(std::make_pair(std::string(name), ConfigValue(rec_type, data_type, value)));
 }
 
 static void
-read_config_string(const char *name, char *val, size_t val_len, bool miss_ok = false)
+config_read_string(const char *name, char *val, size_t val_len, bool miss_ok = false)
 {
   ConfigValueTable::const_iterator config;
 
@@ -518,7 +518,7 @@ ConfigStrFatalError:
 }
 
 static void
-read_config_int(const char *name, int *val, bool miss_ok = false)
+config_read_int(const char *name, int *val, bool miss_ok = false)
 {
   ConfigValueTable::const_iterator config;
 
@@ -542,49 +542,8 @@ ConfigIntFatalError:
   exit(1);
 }
 
-
-void
-get_admin_user()
-{
-  struct passwd *pwd = NULL;
-
-  if (!admin_user)
-    admin_user = (char *)ats_malloc(MAX_LOGIN);
-
-  read_config_string("proxy.config.admin.user_id", admin_user, MAX_LOGIN);
-
-  if (*admin_user) {
-    char *end = admin_user + strlen(admin_user) - 1;
-
-    // Trim trailing spaces.
-    while (end >= admin_user && isspace(*end))
-      end--;
-    *(end + 1) = '\0';
-
-    if (*admin_user == '#') {
-      int uid = atoi(admin_user + 1);
-      if (uid == -1) {
-        // XXX: Can this call hapen after setuid?
-        uid = (int)geteuid();
-      }
-      pwd = getpwuid((uid_t)uid);
-    } else {
-      pwd = getpwnam(admin_user);
-    }
-
-    if (pwd) {
-      admin_uid = pwd->pw_uid;
-      admin_gid = pwd->pw_gid;
-      admin_user_p = true;
-    } else {
-      cop_log(COP_FATAL, "can't get passwd entry for the admin user '%s' - [%d] %s\n", admin_user, errno, strerror(errno));
-      exit(1);
-    }
-  }
-}
-
 static void
-read_config()
+config_reload_records()
 {
   struct stat stat_buf;
   static time_t last_mod = 0;
@@ -592,7 +551,7 @@ read_config()
   char log_filename[PATH_NAME_MAX];
   int tmp_int;
 
-  cop_log_trace("Entering read_config()\n");
+  cop_log_trace("Entering %s()\n", __func__);
   // coverity[fs_check_call]
   if (stat(config_file, &stat_buf) == -1) {
     cop_log(COP_FATAL, "could not stat \"%s\"\n", config_file);
@@ -607,16 +566,16 @@ read_config()
 
   configTable.clear();
 
-  if (RecConfigFileParse(config_file, register_config_variable) != REC_ERR_OKAY) {
+  if (RecConfigFileParse(config_file, config_register_variable) != REC_ERR_OKAY) {
     cop_log(COP_FATAL, "could not parse \"%s\"\n", config_file);
     exit(1);
   }
 
-  read_config_string("proxy.config.manager_binary", manager_binary, sizeof(manager_binary), true);
-  read_config_string("proxy.config.proxy_binary", server_binary, sizeof(server_binary), true);
+  config_read_string("proxy.config.manager_binary", manager_binary, sizeof(manager_binary), true);
+  config_read_string("proxy.config.proxy_binary", server_binary, sizeof(server_binary), true);
   get_admin_user();
 
-  read_config_string("proxy.config.bin_path", bin_path, sizeof(bin_path), true);
+  config_read_string("proxy.config.bin_path", bin_path, sizeof(bin_path), true);
   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));
@@ -626,7 +585,7 @@ read_config()
       exit(1);
     }
   }
-  read_config_string("proxy.config.log.logfile_dir", log_dir, sizeof(log_dir));
+  config_read_string("proxy.config.log.logfile_dir", log_dir, sizeof(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));
@@ -636,29 +595,69 @@ read_config()
       exit(1);
     }
   }
-  read_config_string("proxy.config.output.logfile", log_filename, sizeof(log_filename));
+  config_read_string("proxy.config.output.logfile", log_filename, sizeof(log_filename));
   Layout::relative_to(log_file, sizeof(log_file), log_dir, log_filename);
-  read_config_int("proxy.config.process_manager.mgmt_port", &http_backdoor_port, true);
-  read_config_int("proxy.config.admin.autoconf_port", &autoconf_port, true);
-  read_config_int("proxy.config.cluster.rsport", &rs_port, true);
-  read_config_int("proxy.config.lm.sem_id", &sem_id, true);
+  config_read_int("proxy.config.process_manager.mgmt_port", &http_backdoor_port, true);
+  config_read_int("proxy.config.admin.autoconf_port", &autoconf_port, true);
+  config_read_int("proxy.config.cluster.rsport", &rs_port, true);
+  config_read_int("proxy.config.lm.sem_id", &sem_id, true);
 
 #if defined(linux)
   // TS-1075 : auto-port ::connect DoS on high traffic linux systems
-  read_config_int("proxy.config.cop.source_port", &source_port, true);
+  config_read_int("proxy.config.cop.source_port", &source_port, true);
 #endif
 
-  read_config_int("proxy.local.cluster.type", &tmp_int);
+  config_read_int("proxy.local.cluster.type", &tmp_int);
   cluster_type = static_cast<MgmtClusterType>(tmp_int);
 
-  read_config_string("proxy.config.syslog_facility", syslog_fac_str, sizeof(syslog_fac_str), true);
+  config_read_string("proxy.config.syslog_facility", syslog_fac_str, sizeof(syslog_fac_str), true);
   process_syslog_config();
-  read_config_int("proxy.config.cop.core_signal", &coresig, true);
+  config_read_int("proxy.config.cop.core_signal", &coresig, true);
 
-  read_config_int("proxy.config.cop.linux_min_swapfree_kb", &check_memory_min_swapfree_kb, true);
-  read_config_int("proxy.config.cop.linux_min_memfree_kb", &check_memory_min_memfree_kb, true);
+  config_read_int("proxy.config.cop.linux_min_swapfree_kb", &check_memory_min_swapfree_kb, true);
+  config_read_int("proxy.config.cop.linux_min_memfree_kb", &check_memory_min_memfree_kb, true);
 
-  cop_log_trace("Leaving read_config()\n");
+  cop_log_trace("Leaving %s()\n", __func__);
+}
+
+static void
+get_admin_user()
+{
+  struct passwd *pwd = NULL;
+
+  if (!admin_user)
+    admin_user = (char *)ats_malloc(MAX_LOGIN);
+
+  config_read_string("proxy.config.admin.user_id", admin_user, MAX_LOGIN);
+
+  if (*admin_user) {
+    char *end = admin_user + strlen(admin_user) - 1;
+
+    // Trim trailing spaces.
+    while (end >= admin_user && isspace(*end))
+      end--;
+    *(end + 1) = '\0';
+
+    if (*admin_user == '#') {
+      int uid = atoi(admin_user + 1);
+      if (uid == -1) {
+        // XXX: Can this call hapen after setuid?
+        uid = (int)geteuid();
+      }
+      pwd = getpwuid((uid_t)uid);
+    } else {
+      pwd = getpwnam(admin_user);
+    }
+
+    if (pwd) {
+      admin_uid = pwd->pw_uid;
+      admin_gid = pwd->pw_gid;
+      admin_user_p = true;
+    } else {
+      cop_log(COP_FATAL, "can't get passwd entry for the admin user '%s' - [%d] %s\n", admin_user, errno, strerror(errno));
+      exit(1);
+    }
+  }
 }
 
 static void
@@ -1579,7 +1578,7 @@ check(void *arg)
     }
 
     // Re-read the config file information
-    read_config();
+    config_reload_records();
 
     // Check to make sure the programs are running
     check_programs();