This is an automated email from the ASF dual-hosted git repository.

dragon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 27cec04  New layout structure with std string & basic string view
27cec04 is described below

commit 27cec04b9bd345a5fadb3bd505336c41785b7e1b
Author: Xavier Chi <chitianha...@gmail.com>
AuthorDate: Tue Aug 8 15:15:45 2017 -0500

    New layout structure with std string & basic string view
---
 cmd/traffic_cop/traffic_cop.cc           |  46 +++++------
 cmd/traffic_crashlog/traffic_crashlog.cc |   2 +-
 cmd/traffic_layout/traffic_layout.cc     |  28 ++++---
 cmd/traffic_manager/metrics.cc           |   2 +-
 cmd/traffic_manager/traffic_manager.cc   |  39 +++++-----
 iocore/cache/Store.cc                    |  12 ++-
 iocore/net/SSLConfig.cc                  |  10 +--
 lib/cppapi/Transaction.cc                |   4 +-
 lib/records/I_RecCore.h                  |  27 +++----
 lib/records/RecCore.cc                   |  38 ++++-----
 lib/ts/I_Layout.h                        |  56 ++++++-------
 lib/ts/Layout.cc                         | 130 +++++++++----------------------
 lib/ts/Makefile.am                       |   4 +-
 lib/ts/ink_memory.h                      |  10 +++
 lib/ts/unit-tests/test_layout.cpp        |  89 +++++++++++++++++++++
 mgmt/Alarms.cc                           |   2 +-
 mgmt/FileManager.cc                      |   2 +-
 mgmt/LocalManager.cc                     |  24 +++---
 mgmt/ProcessManager.cc                   |  10 +--
 mgmt/Rollback.cc                         |   4 +-
 mgmt/api/CoreAPIRemote.cc                |   2 +-
 mgmt/api/NetworkUtilsRemote.cc           |   4 +-
 proxy/Crash.cc                           |   2 +-
 proxy/InkAPI.cc                          |  16 ++--
 proxy/Main.cc                            |  36 ++++-----
 proxy/Plugin.cc                          |   2 +-
 proxy/http/remap/RemapConfig.cc          |   2 +-
 proxy/logging/LogConfig.cc               |   2 +-
 proxy/logging/LogStandalone.cc           |   6 +-
 proxy/logstats.cc                        |   6 +-
 30 files changed, 322 insertions(+), 295 deletions(-)

diff --git a/cmd/traffic_cop/traffic_cop.cc b/cmd/traffic_cop/traffic_cop.cc
index c4ea158..4536e25 100644
--- a/cmd/traffic_cop/traffic_cop.cc
+++ b/cmd/traffic_cop/traffic_cop.cc
@@ -543,7 +543,7 @@ ConfigIntFatalError:
   exit(1);
 }
 
-static char *
+static std::string
 config_read_runtime_dir()
 {
   char state_dir[PATH_NAME_MAX];
@@ -553,11 +553,11 @@ config_read_runtime_dir()
   if (strlen(state_dir) > 0) {
     return Layout::get()->relative(state_dir);
   } else {
-    return ats_strdup(Layout::get()->runtimedir);
+    return Layout::get()->runtimedir;
   }
 }
 
-static char *
+static std::string
 config_read_sysconfig_dir()
 {
   char sysconfig_dir[PATH_NAME_MAX];
@@ -567,11 +567,11 @@ config_read_sysconfig_dir()
   if (strlen(sysconfig_dir) > 0) {
     return Layout::get()->relative(sysconfig_dir);
   } else {
-    return ats_strdup(Layout::get()->sysconfdir);
+    return Layout::get()->sysconfdir;
   }
 }
 
-static char *
+static std::string
 config_read_bin_dir()
 {
   char bindir[PATH_NAME_MAX];
@@ -582,11 +582,11 @@ config_read_bin_dir()
   if (strlen(bindir) > 0) {
     return Layout::get()->relative(bindir);
   } else {
-    return ats_strdup(Layout::get()->bindir);
+    return Layout::get()->bindir;
   }
 }
 
-static char *
+static std::string
 config_read_log_dir()
 {
   char logdir[PATH_NAME_MAX];
@@ -596,7 +596,7 @@ config_read_log_dir()
   if (strlen(logdir) > 0) {
     return Layout::get()->relative(logdir);
   } else {
-    return ats_strdup(Layout::get()->logdir);
+    return Layout::get()->logdir;
   }
 }
 
@@ -608,8 +608,8 @@ config_reload_records()
   char log_filename[PATH_NAME_MAX];
   int tmp_int = 3;
 
-  ats_scoped_str bindir;
-  ats_scoped_str logdir;
+  std::string bindir;
+  std::string logdir;
 
   cop_log_trace("Entering %s()\n", __func__);
   // coverity[fs_check_call]
@@ -637,15 +637,15 @@ config_reload_records()
   get_admin_user();
 
   bindir = config_read_bin_dir();
-  if (access(bindir, R_OK) == -1) {
-    cop_log(COP_FATAL, "could not access() \"%s\"\n", (const char *)bindir);
+  if (access(bindir.c_str(), R_OK) == -1) {
+    cop_log(COP_FATAL, "could not access() \"%s\"\n", bindir.c_str());
     cop_log(COP_FATAL, "please set 'proxy.config.bin_path' \n");
     exit(1);
   }
 
   logdir = config_read_log_dir();
-  if (access(logdir, W_OK) == -1) {
-    cop_log(COP_FATAL, "could not access() \"%s\"\n", (const char *)logdir);
+  if (access(logdir.c_str(), W_OK) == -1) {
+    cop_log(COP_FATAL, "could not access() \"%s\"\n", logdir.c_str());
     cop_log(COP_FATAL, "please set 'proxy.config.log.logfile_dir' \n");
     exit(1);
   }
@@ -741,7 +741,7 @@ static void
 spawn_manager()
 {
   char prog[PATH_NAME_MAX];
-  ats_scoped_str bindir(config_read_bin_dir());
+  std::string bindir(config_read_bin_dir());
 
   cop_log_trace("Entering spawn_manager()\n");
 
@@ -1503,8 +1503,8 @@ check(void *arg)
 
     // We do this after the first round of checks, since the first "check" 
will spawn traffic_manager
     if (!mgmt_init) {
-      ats_scoped_str runtimedir(config_read_runtime_dir());
-      TSInit(runtimedir, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS));
+      std::string runtimedir(config_read_runtime_dir());
+      TSInit(runtimedir.c_str(), 
static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS));
       mgmt_init = true;
 
       // Allow a configurable longer sleep init time
@@ -1627,13 +1627,13 @@ static void
 init_config_file()
 {
   struct stat info;
-  ats_scoped_str config_dir;
+  std::string config_dir;
 
   cop_log_trace("Entering init_config_file()\n");
 
   config_dir = config_read_sysconfig_dir();
-  if (stat(config_dir, &info) < 0) {
-    cop_log(COP_FATAL, "unable to locate config directory '%s'\n", (const char 
*)config_dir);
+  if (stat(config_dir.c_str(), &info) < 0) {
+    cop_log(COP_FATAL, "unable to locate config directory '%s'\n", 
config_dir.c_str());
     cop_log(COP_FATAL, " please try setting correct root path in env variable 
TS_ROOT \n");
     exit(1);
   }
@@ -1642,8 +1642,8 @@ init_config_file()
   if (stat(config_file, &info) < 0) {
     Layout::relative_to(config_file, sizeof(config_file), config_dir, 
"records.config");
     if (stat(config_file, &info) < 0) {
-      cop_log(COP_FATAL, "unable to locate \"%s/records.config\" or 
\"%s/records.config.shadow\"\n", (const char *)config_dir,
-              (const char *)config_dir);
+      cop_log(COP_FATAL, "unable to locate \"%s/records.config\" or 
\"%s/records.config.shadow\"\n", config_dir.c_str(),
+              config_dir.c_str());
       exit(1);
     }
   }
@@ -1667,7 +1667,7 @@ init()
   init_config_file();
   config_reload_records();
 
-  runtime_dir = config_read_runtime_dir();
+  runtime_dir = ats_stringdup(config_read_runtime_dir());
   if (stat(runtime_dir, &info) < 0) {
     cop_log(COP_FATAL, "unable to locate local state directory '%s'\n", 
runtime_dir);
     cop_log(COP_FATAL, " please try setting correct root path in either env 
variable TS_ROOT \n");
diff --git a/cmd/traffic_crashlog/traffic_crashlog.cc 
b/cmd/traffic_crashlog/traffic_crashlog.cc
index faf98dc..54b4755 100644
--- a/cmd/traffic_crashlog/traffic_crashlog.cc
+++ b/cmd/traffic_crashlog/traffic_crashlog.cc
@@ -65,7 +65,7 @@ crashlog_name()
 {
   char filename[64];
   struct tm now = timestamp();
-  ats_scoped_str logdir(RecConfigReadLogDir());
+  std::string logdir(RecConfigReadLogDir());
   ats_scoped_str pathname;
 
   strftime(filename, sizeof(filename), "crash-%Y-%m-%d-%H%M%S.log", &now);
diff --git a/cmd/traffic_layout/traffic_layout.cc 
b/cmd/traffic_layout/traffic_layout.cc
index 82a33c8..ec984f6 100644
--- a/cmd/traffic_layout/traffic_layout.cc
+++ b/cmd/traffic_layout/traffic_layout.cc
@@ -28,6 +28,8 @@
 #include "I_RecProcess.h"
 #include "RecordsConfig.h"
 
+#include <iostream>
+
 // Command line arguments (parsing)
 struct CommandLineArgs {
   int layout;
@@ -128,18 +130,14 @@ produce_features(bool json)
   }
 }
 
-static void
-print_var(const char *name, char *value, bool json, bool free = true, bool 
last = false)
+void
+print_var(ts::string_view const &name, ts::string_view const &value, bool 
json, bool last = false)
 {
-  if (json) {
-    printf(R"(    "%s": "%s"%s)", name, value, last ? "\n" : ",\n");
-  } else {
-    printf("%s: %s\n", name, value);
-  }
-
-  if (free) {
-    ats_free(value);
-  }
+  if (json)
+    printf(R"(    "%.*s": "%.*s"%s)", static_cast<int>(name.size()), 
name.data(), static_cast<int>(value.size()), value.data(),
+           last ? "\n" : ",\n");
+  else
+    printf("%.*s: %.*s\n", static_cast<int>(name.size()), name.data(), 
static_cast<int>(value.size()), value.data());
 }
 
 static void
@@ -153,14 +151,14 @@ produce_layout(bool json)
   if (json) {
     printf("{\n");
   }
-  print_var("PREFIX", Layout::get()->prefix, json, false); // Don't free this
+  print_var("PREFIX", Layout::get()->prefix, json);
   print_var("BINDIR", RecConfigReadBinDir(), json);
   print_var("SYSCONFDIR", RecConfigReadConfigDir(), json);
-  print_var("LIBDIR", Layout::get()->libdir, json, false); // Don't free this
+  print_var("LIBDIR", Layout::get()->libdir, json);
   print_var("LOGDIR", RecConfigReadLogDir(), json);
   print_var("RUNTIMEDIR", RecConfigReadRuntimeDir(), json);
   print_var("PLUGINDIR", RecConfigReadPluginDir(), json);
-  print_var("INCLUDEDIR", Layout::get()->includedir, json, false); // Dont' 
free this
+  print_var("INCLUDEDIR", Layout::get()->includedir, json);
   print_var("SNAPSHOTDIR", RecConfigReadSnapshotDir(), json);
 
   print_var("records.config", RecConfigReadConfigPath(nullptr, 
REC_CONFIG_FILE), json);
@@ -170,7 +168,7 @@ produce_layout(bool json)
   print_var("storage.config", 
RecConfigReadConfigPath("proxy.config.cache.storage_filename"), json);
   print_var("hosting.config", 
RecConfigReadConfigPath("proxy.config.cache.hosting_filename"), json);
   print_var("volume.config", 
RecConfigReadConfigPath("proxy.config.cache.volume_filename"), json);
-  print_var("ip_allow.config", 
RecConfigReadConfigPath("proxy.config.cache.ip_allow.filename"), json, true, 
true);
+  print_var("ip_allow.config", 
RecConfigReadConfigPath("proxy.config.cache.ip_allow.filename"), json, true);
   if (json) {
     printf("}\n");
   }
diff --git a/cmd/traffic_manager/metrics.cc b/cmd/traffic_manager/metrics.cc
index eda0ae7..b4d0838 100644
--- a/cmd/traffic_manager/metrics.cc
+++ b/cmd/traffic_manager/metrics.cc
@@ -341,7 +341,7 @@ bool
 metrics_binding_configure(BindingInstance &binding)
 {
   ats_scoped_str sysconfdir(RecConfigReadConfigDir());
-  ats_scoped_str config(Layout::get()->relative_to(sysconfdir, 
"metrics.config"));
+  ats_scoped_str config(Layout::get()->relative_to(sysconfdir.get(), 
"metrics.config"));
 
   return binding.require(config.get());
 }
diff --git a/cmd/traffic_manager/traffic_manager.cc 
b/cmd/traffic_manager/traffic_manager.cc
index 5575fa0..c3d23e2 100644
--- a/cmd/traffic_manager/traffic_manager.cc
+++ b/cmd/traffic_manager/traffic_manager.cc
@@ -163,7 +163,7 @@ is_server_idle()
 static void
 check_lockfile()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
+  std::string rundir(RecConfigReadRuntimeDir());
   char lockfile[PATH_NAME_MAX];
   int err;
   pid_t holding_pid;
@@ -299,17 +299,17 @@ initSignalHandlers()
 static void
 init_dirs()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str sysconfdir(RecConfigReadConfigDir());
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string sysconfdir(RecConfigReadConfigDir());
 
-  if (access(sysconfdir, R_OK) == -1) {
-    mgmt_elog(0, "unable to access() config directory '%s': %d, %s\n", (const 
char *)sysconfdir, errno, strerror(errno));
+  if (access(sysconfdir.c_str(), R_OK) == -1) {
+    mgmt_elog(0, "unable to access() config directory '%s': %d, %s\n", 
sysconfdir.c_str(), errno, strerror(errno));
     mgmt_elog(0, "please set the 'TS_ROOT' environment variable\n");
     ::exit(1);
   }
 
-  if (access(rundir, R_OK) == -1) {
-    mgmt_elog(0, "unable to access() local state directory '%s': %d, %s\n", 
(const char *)rundir, errno, strerror(errno));
+  if (access(rundir.c_str(), R_OK) == -1) {
+    mgmt_elog(0, "unable to access() local state directory '%s': %d, %s\n", 
rundir.c_str(), errno, strerror(errno));
     mgmt_elog(0, "please set 'proxy.config.local_state_dir'\n");
     ::exit(1);
   }
@@ -318,14 +318,14 @@ init_dirs()
 static void
 chdir_root()
 {
-  const char *prefix = Layout::get()->prefix;
+  std::string prefix = Layout::get()->prefix;
 
-  if (chdir(prefix) < 0) {
-    mgmt_elog(0, "unable to change to root directory \"%s\" [%d '%s']\n", 
prefix, errno, strerror(errno));
+  if (chdir(prefix.c_str()) < 0) {
+    mgmt_elog(0, "unable to change to root directory \"%s\" [%d '%s']\n", 
prefix.c_str(), errno, strerror(errno));
     mgmt_elog(0, " please set correct path in env variable TS_ROOT \n");
     exit(1);
   } else {
-    mgmt_log("[TrafficManager] using root directory '%s'\n", prefix);
+    mgmt_log("[TrafficManager] using root directory '%s'\n", prefix.c_str());
   }
 }
 
@@ -418,7 +418,7 @@ main(int argc, const char **argv)
 
   // Before accessing file system initialize Layout engine
   Layout::create();
-  mgmt_path = Layout::get()->sysconfdir;
+  mgmt_path = Layout::get()->sysconfdir.c_str();
 
   // Set up the application version info
   appVersionInfo.setup(PACKAGE_NAME, "traffic_manager", PACKAGE_VERSION, 
__DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
@@ -637,9 +637,9 @@ main(int argc, const char **argv)
   Debug("lm", "Created Web Agent thread (%" PRId64 ")", (int64_t)synthThrId);
 
   // Setup the API and event sockets
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str apisock(Layout::relative_to(rundir, 
MGMTAPI_MGMT_SOCKET_NAME));
-  ats_scoped_str eventsock(Layout::relative_to(rundir, 
MGMTAPI_EVENT_SOCKET_NAME));
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string apisock(Layout::relative_to(rundir, MGMTAPI_MGMT_SOCKET_NAME));
+  std::string eventsock(Layout::relative_to(rundir, 
MGMTAPI_EVENT_SOCKET_NAME));
 
   mode_t oldmask = umask(0);
   mode_t newmode = api_socket_is_restricted() ? 00700 : 00777;
@@ -648,17 +648,16 @@ main(int argc, const char **argv)
   int eventapiFD        = -1; // FD for the api and clients to handle event 
callbacks
   char mgmtapiFailMsg[] = "Traffic server management API service Interface 
Failed to Initialize.";
 
-  mgmtapiFD = bind_unix_domain_socket(apisock, newmode);
+  mgmtapiFD = bind_unix_domain_socket(apisock.c_str(), newmode);
   if (mgmtapiFD == -1) {
-    mgmt_log("[WebIntrMain] Unable to set up socket for handling management 
API calls. API socket path = %s\n",
-             (const char *)apisock);
+    mgmt_log("[WebIntrMain] Unable to set up socket for handling management 
API calls. API socket path = %s\n", apisock.c_str());
     lmgmt->alarm_keeper->signalAlarm(MGMT_ALARM_WEB_ERROR, mgmtapiFailMsg);
   }
 
-  eventapiFD = bind_unix_domain_socket(eventsock, newmode);
+  eventapiFD = bind_unix_domain_socket(eventsock.c_str(), newmode);
   if (eventapiFD == -1) {
     mgmt_log("[WebIntrMain] Unable to set up so for handling management API 
event calls. Event Socket path: %s\n",
-             (const char *)eventsock);
+             eventsock.c_str());
   }
 
   umask(oldmask);
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index cb41c26..b6e0ef2 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -392,20 +392,18 @@ Store::read_config()
       }
     }
 
-    char *pp = Layout::get()->relative(path);
+    std::string pp = Layout::get()->relative(path);
 
     ns = new Span;
-    Debug("cache_init", "Store::read_config - ns = new Span; 
ns->init(\"%s\",%" PRId64 "), forced volume=%d%s%s", pp, size,
+    Debug("cache_init", "Store::read_config - ns = new Span; 
ns->init(\"%s\",%" PRId64 "), forced volume=%d%s%s", pp.c_str(), size,
           volume_num, seed ? " id=" : "", seed ? seed : "");
-    if ((err = ns->init(pp, size))) {
-      RecSignalWarning(REC_SIGNAL_SYSTEM_ERROR, "could not initialize storage 
\"%s\" [%s]", pp, err);
-      Debug("cache_init", "Store::read_config - could not initialize storage 
\"%s\" [%s]", pp, err);
+    if ((err = ns->init(pp.c_str(), size))) {
+      RecSignalWarning(REC_SIGNAL_SYSTEM_ERROR, "could not initialize storage 
\"%s\" [%s]", pp.c_str(), err);
+      Debug("cache_init", "Store::read_config - could not initialize storage 
\"%s\" [%s]", pp.c_str(), err);
       delete ns;
-      ats_free(pp);
       continue;
     }
 
-    ats_free(pp);
     n_dsstore++;
 
     // Set side values if present.
diff --git a/iocore/net/SSLConfig.cc b/iocore/net/SSLConfig.cc
index 803ca57..f46e51d 100644
--- a/iocore/net/SSLConfig.cc
+++ b/iocore/net/SSLConfig.cc
@@ -141,16 +141,16 @@ set_paths_helper(const char *path, const char *filename, 
char **final_path, char
 {
   if (final_path) {
     if (path && path[0] != '/') {
-      *final_path = RecConfigReadPrefixPath(nullptr, path);
+      *final_path = ats_stringdup(RecConfigReadPrefixPath(nullptr, path));
     } else if (!path || path[0] == '\0') {
-      *final_path = RecConfigReadConfigDir();
+      *final_path = ats_stringdup(RecConfigReadConfigDir());
     } else {
       *final_path = ats_strdup(path);
     }
   }
 
   if (final_filename) {
-    *final_filename = filename ? Layout::get()->relative_to(path, filename) : 
nullptr;
+    *final_filename = filename ? 
ats_stringdup(Layout::get()->relative_to(path, filename)) : nullptr;
   }
 }
 
@@ -176,7 +176,7 @@ SSLConfigParams::initialize()
   REC_ReadConfigInt32(clientCertLevel, 
"proxy.config.ssl.client.certification_level");
   REC_ReadConfigStringAlloc(cipherSuite, 
"proxy.config.ssl.server.cipher_suite");
   REC_ReadConfigStringAlloc(client_cipherSuite, 
"proxy.config.ssl.client.cipher_suite");
-  dhparamsFile = 
RecConfigReadConfigPath("proxy.config.ssl.server.dhparams_file");
+  dhparamsFile = 
ats_stringdup(RecConfigReadConfigPath("proxy.config.ssl.server.dhparams_file"));
 
   int options;
   int client_ssl_options = 0;
@@ -256,7 +256,7 @@ SSLConfigParams::initialize()
   set_paths_helper(serverCertRelativePath, nullptr, &serverCertPathOnly, 
nullptr);
   ats_free(serverCertRelativePath);
 
-  configFilePath = 
RecConfigReadConfigPath("proxy.config.ssl.server.multicert.filename");
+  configFilePath = 
ats_stringdup(RecConfigReadConfigPath("proxy.config.ssl.server.multicert.filename"));
   REC_ReadConfigInteger(configExitOnLoadError, 
"proxy.config.ssl.server.multicert.exit_on_load_fail");
 
   REC_ReadConfigStringAlloc(ssl_server_private_key_path, 
"proxy.config.ssl.server.private_key.path");
diff --git a/lib/cppapi/Transaction.cc b/lib/cppapi/Transaction.cc
index a2b7f66..afc2019 100644
--- a/lib/cppapi/Transaction.cc
+++ b/lib/cppapi/Transaction.cc
@@ -397,9 +397,9 @@ Transaction::getCacheStatus()
 void
 Transaction::redirectTo(std::string const &url)
 {
-  char *s = ats_strdup(url.c_str());
+  std::string s = url;
   // Must re-alloc the string locally because ownership is transferred to the 
transaction.
-  TSHttpTxnRedirectUrlSet(state_->txn_, s, url.length());
+  TSHttpTxnRedirectUrlSet(state_->txn_, s.c_str(), url.length());
 }
 
 namespace
diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h
index da904c7..ff39339 100644
--- a/lib/records/I_RecCore.h
+++ b/lib/records/I_RecCore.h
@@ -49,40 +49,33 @@ void RecConfigFileInit(void);
 int RecConfigFileParse(const char *path, RecConfigEntryCallback handler, bool 
inc_version);
 
 // Return a copy of the system's configuration directory, taking 
proxy.config.config_dir into account. The
-// caller MUST release the result with ats_free().
-char *RecConfigReadConfigDir();
+std::string RecConfigReadConfigDir();
 
 // Return a copy of the system's local state directory, taking 
proxy.config.local_state_dir into account. The
-// caller MUST release the result with ats_free().
-char *RecConfigReadRuntimeDir();
+std::string RecConfigReadRuntimeDir();
 
 // Return a copy of the system's snapshot directory, taking 
proxy.config.snapshot_dir into account. The caller
-// MUST release the result with ats_free().
-char *RecConfigReadSnapshotDir();
+std::string RecConfigReadSnapshotDir();
 
 // Return a copy of the system's log directory, taking 
proxy.config.log.logfile_dir into account. The caller
-// MUST release the result with ats_free().
-char *RecConfigReadLogDir();
+std::string RecConfigReadLogDir();
 
 // Return a copy of the system's bin directory, taking proxy.config.bin_path 
into account. The caller MUST
-// release the result with ats_free().
-char *RecConfigReadBinDir();
+std::string RecConfigReadBinDir();
 
 // Return a copy of the system's plugin directory, taking 
proxy.config.plugin.plugin_dir into account. The caller MUST
-// release the result with ats_free().
-char *RecConfigReadPluginDir();
+std::string RecConfigReadPluginDir();
 
 // 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, nullptr is returned. The caller MUST release the result with 
ats_free().
-char *RecConfigReadConfigPath(const char *file_variable, const char 
*default_value = nullptr);
+// value, nullptr is returned.
+std::string RecConfigReadConfigPath(const char *file_variable, const char 
*default_value = nullptr);
 
 // This is the same as RecConfigReadConfigPath, except it makes the paths 
relative to $PREFIX.
-char *RecConfigReadPrefixPath(const char *file_variable, const char 
*default_value = nullptr);
+std::string RecConfigReadPrefixPath(const char *file_variable, const char 
*default_value = nullptr);
 
 // Return a copy of the persistent stats file. This is 
$RUNTIMEDIR/records.snap.
-// The caller MUST release the result with ats_free().
-char *RecConfigReadPersistentStatsPath();
+std::string RecConfigReadPersistentStatsPath();
 
 // 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.
diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc
index ed8632e..5069782 100644
--- a/lib/records/RecCore.cc
+++ b/lib/records/RecCore.cc
@@ -216,10 +216,10 @@ RecCoreInit(RecModeT mode_type, Diags *_diags)
 
     ink_mutex_init(&g_rec_config_lock);
 
-    g_rec_config_fpath = RecConfigReadConfigPath(nullptr, REC_CONFIG_FILE 
REC_SHADOW_EXT);
+    g_rec_config_fpath = ats_stringdup(RecConfigReadConfigPath(nullptr, 
REC_CONFIG_FILE REC_SHADOW_EXT));
     if (RecFileExists(g_rec_config_fpath) == REC_ERR_FAIL) {
       ats_free((char *)g_rec_config_fpath);
-      g_rec_config_fpath = RecConfigReadConfigPath(nullptr, REC_CONFIG_FILE);
+      g_rec_config_fpath = ats_stringdup(RecConfigReadConfigPath(nullptr, 
REC_CONFIG_FILE));
       if (RecFileExists(g_rec_config_fpath) == REC_ERR_FAIL) {
         RecLog(DL_Warning, "Could not find '%s', system will run with 
defaults\n", REC_CONFIG_FILE);
         file_exists = false;
@@ -1124,7 +1124,7 @@ REC_readString(const char *name, bool *found, bool lock)
 // overrides specially here. Normally we would override the configuration
 // variable when we read records.config but to avoid the bootstrapping
 // problem, we make an explicit check here.
-char *
+std::string
 RecConfigReadConfigDir()
 {
   char buf[PATH_NAME_MAX] = {0};
@@ -1138,14 +1138,14 @@ RecConfigReadConfigDir()
   if (strlen(buf) > 0) {
     return Layout::get()->relative(buf);
   } else {
-    return ats_strdup(Layout::get()->sysconfdir);
+    return Layout::get()->sysconfdir;
   }
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadRuntimeDir
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadRuntimeDir()
 {
   char buf[PATH_NAME_MAX];
@@ -1155,14 +1155,14 @@ RecConfigReadRuntimeDir()
   if (strlen(buf) > 0) {
     return Layout::get()->relative(buf);
   } else {
-    return ats_strdup(Layout::get()->runtimedir);
+    return Layout::get()->runtimedir;
   }
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadLogDir
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadLogDir()
 {
   char buf[PATH_NAME_MAX];
@@ -1172,14 +1172,14 @@ RecConfigReadLogDir()
   if (strlen(buf) > 0) {
     return Layout::get()->relative(buf);
   } else {
-    return ats_strdup(Layout::get()->logdir);
+    return Layout::get()->logdir;
   }
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadBinDir
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadBinDir()
 {
   char buf[PATH_NAME_MAX];
@@ -1189,14 +1189,14 @@ RecConfigReadBinDir()
   if (strlen(buf) > 0) {
     return Layout::get()->relative(buf);
   } else {
-    return ats_strdup(Layout::get()->bindir);
+    return Layout::get()->bindir;
   }
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadPluginDir
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadPluginDir()
 {
   return RecConfigReadPrefixPath("proxy.config.plugin.plugin_dir");
@@ -1205,7 +1205,7 @@ RecConfigReadPluginDir()
 //-------------------------------------------------------------------------
 // RecConfigReadSnapshotDir.
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadSnapshotDir()
 {
   return RecConfigReadConfigPath("proxy.config.snapshot_dir", "snapshots");
@@ -1214,10 +1214,10 @@ RecConfigReadSnapshotDir()
 //-------------------------------------------------------------------------
 // RecConfigReadConfigPath
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadConfigPath(const char *file_variable, const char *default_value)
 {
-  ats_scoped_str sysconfdir(RecConfigReadConfigDir());
+  std::string sysconfdir(RecConfigReadConfigDir());
 
   // If the file name is in a configuration variable, look it up first ...
   if (file_variable) {
@@ -1235,13 +1235,13 @@ RecConfigReadConfigPath(const char *file_variable, 
const char *default_value)
     return Layout::get()->relative_to(sysconfdir, default_value);
   }
 
-  return nullptr;
+  return {};
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadPrefixPath
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadPrefixPath(const char *file_variable, const char *default_value)
 {
   char buf[PATH_NAME_MAX];
@@ -1260,16 +1260,16 @@ RecConfigReadPrefixPath(const char *file_variable, 
const char *default_value)
     return Layout::get()->relative_to(Layout::get()->prefix, default_value);
   }
 
-  return nullptr;
+  return {};
 }
 
 //-------------------------------------------------------------------------
 // RecConfigReadPersistentStatsPath
 //-------------------------------------------------------------------------
-char *
+std::string
 RecConfigReadPersistentStatsPath()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
+  std::string rundir(RecConfigReadRuntimeDir());
   return Layout::relative_to(rundir, REC_RAW_STATS_FILE);
 }
 
diff --git a/lib/ts/I_Layout.h b/lib/ts/I_Layout.h
index dd6d47f..d23b07a 100644
--- a/lib/ts/I_Layout.h
+++ b/lib/ts/I_Layout.h
@@ -31,50 +31,44 @@
 #ifndef _I_Layout_h
 #define _I_Layout_h
 
+// use std string and string view for layout
+#include <string>
+#include "ts/string_view.h"
+
 /**
   The Layout is a simple place holder for the distribution layout.
 
  */
 struct Layout {
-  Layout(const char *prefix = 0);
+  Layout(ts::string_view const _prefix = {});
   ~Layout();
 
   /**
    Return file path relative to Layout->prefix
-   Memory is allocated, so use ats_free() when no longer needed
 
   */
-  char *relative(const char *file);
+  std::string relative(ts::string_view file);
 
   /**
    update the sysconfdir to a test conf dir
-   */
-  void update_sysconfdir(const char *dir);
-
-  /**
-   Return file path relative to Layout->prefix
-   Store the path to buf. The buf should be large eough to store
-   PATH_NAME_MAX characters
 
    */
-  void relative(char *buf, size_t bufsz, const char *file);
+  void update_sysconfdir(ts::string_view dir);
 
   /**
    Return file path relative to dir
-   Memory is allocated, so use ats_free() when no longer needed
    Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
 
   */
-  static char *relative_to(const char *dir, const char *file);
+  static std::string relative_to(ts::string_view dir, ts::string_view file);
 
   /**
    Return file path relative to dir
    Store the path to buf. The buf should be large eough to store
-   PATH_NAME_MAX characters
    Example usage: Layout::relative_to(default_layout()->sysconfdir, "foo.bar");
 
   */
-  static void relative_to(char *buf, size_t bufsz, const char *dir, const char 
*file);
+  static void relative_to(char *buf, size_t bufsz, ts::string_view dir, 
ts::string_view file);
 
   /**
    Creates a Layout Object with the given prefix.  If no
@@ -82,7 +76,7 @@ struct Layout {
    at the compile time.
 
   */
-  static void create(const char *prefix = 0);
+  static void create(ts::string_view const prefix = {});
 
   /**
    Returns the Layout object created by create_default_layout().
@@ -90,21 +84,21 @@ struct Layout {
   */
   static Layout *get();
 
-  char *prefix        = nullptr;
-  char *exec_prefix   = nullptr;
-  char *bindir        = nullptr;
-  char *sbindir       = nullptr;
-  char *sysconfdir    = nullptr;
-  char *datadir       = nullptr;
-  char *includedir    = nullptr;
-  char *libdir        = nullptr;
-  char *libexecdir    = nullptr;
-  char *localstatedir = nullptr;
-  char *runtimedir    = nullptr;
-  char *logdir        = nullptr;
-  char *mandir        = nullptr;
-  char *infodir       = nullptr;
-  char *cachedir      = nullptr;
+  std::string prefix;
+  std::string exec_prefix;
+  std::string bindir;
+  std::string sbindir;
+  std::string sysconfdir;
+  std::string datadir;
+  std::string includedir;
+  std::string libdir;
+  std::string libexecdir;
+  std::string localstatedir;
+  std::string runtimedir;
+  std::string logdir;
+  std::string mandir;
+  std::string infodir;
+  std::string cachedir;
 };
 
 #endif
diff --git a/lib/ts/Layout.cc b/lib/ts/Layout.cc
index 483dcf1..cb3c7d8 100644
--- a/lib/ts/Layout.cc
+++ b/lib/ts/Layout.cc
@@ -41,134 +41,95 @@ Layout::get()
 }
 
 void
-Layout::create(const char *prefix)
+Layout::create(ts::string_view const prefix)
 {
   if (layout == nullptr) {
     layout = new Layout(prefix);
   }
 }
 
-static char *
-layout_relative(const char *root, const char *file)
+static void
+_relative(char *path, size_t buffsz, ts::string_view root, ts::string_view 
file)
 {
-  char path[PATH_NAME_MAX];
-
-  if (ink_filepath_merge(path, PATH_NAME_MAX, root, file, 
INK_FILEPATH_TRUENAME)) {
+  if (ink_filepath_merge(path, buffsz, root.data(), file.data(), 
INK_FILEPATH_TRUENAME)) {
     int err = errno;
     // Log error
     if (err == EACCES) {
-      ink_error("Cannot merge path '%s' above the root '%s'\n", file, root);
+      ink_fatal("Cannot merge path '%s' above the root '%s'\n", file.data(), 
root.data());
     } else if (err == E2BIG) {
-      ink_error("Exceeding file name length limit of %d characters\n", 
PATH_NAME_MAX);
+      ink_fatal("Exceeding file name length limit of %d characters\n", 
PATH_NAME_MAX);
     } else {
       // TODO: Make some pretty errors.
-      ink_error("Cannot merge '%s' with '%s' error=%d\n", file, root, err);
+      ink_fatal("Cannot merge '%s' with '%s' error=%d\n", file.data(), 
root.data(), err);
     }
-    return nullptr;
   }
-  return ats_strdup(path);
 }
 
-char *
-Layout::relative(const char *file)
+static std::string
+layout_relative(ts::string_view root, ts::string_view file)
 {
-  return layout_relative(prefix, file);
+  char path[PATH_NAME_MAX];
+  std::string ret;
+  _relative(path, PATH_NAME_MAX, root, file);
+  ret = path;
+  return ret;
 }
 
-void
-Layout::relative(char *buf, size_t bufsz, const char *file)
+std::string
+Layout::relative(ts::string_view file)
 {
-  char path[PATH_NAME_MAX];
-
-  if (ink_filepath_merge(path, PATH_NAME_MAX, prefix, file, 
INK_FILEPATH_TRUENAME)) {
-    int err = errno;
-    // Log error
-    if (err == EACCES) {
-      ink_error("Cannot merge path '%s' above the root '%s'\n", file, prefix);
-    } else if (err == E2BIG) {
-      ink_error("Exceeding file name length limit of %d characters\n", 
PATH_NAME_MAX);
-    } else {
-      // TODO: Make some pretty errors.
-      ink_error("Cannot merge '%s' with '%s' error=%d\n", file, prefix, err);
-    }
-    return;
-  }
-  size_t path_len = strlen(path) + 1;
-  if (path_len > bufsz) {
-    ink_error("Provided buffer is too small: %zu, required %zu\n", bufsz, 
path_len);
-  } else {
-    ink_strlcpy(buf, path, bufsz);
-  }
+  return layout_relative(prefix, file);
 }
 
+// for updating the structure sysconfdir
 void
-Layout::update_sysconfdir(const char *dir)
+Layout::update_sysconfdir(ts::string_view dir)
 {
-  if (sysconfdir) {
-    ats_free(sysconfdir);
-  }
-
-  sysconfdir = ats_strdup(dir);
+  sysconfdir.assign(dir.data(), dir.size());
 }
 
-char *
-Layout::relative_to(const char *dir, const char *file)
+std::string
+Layout::relative_to(ts::string_view dir, ts::string_view file)
 {
   return layout_relative(dir, file);
 }
 
 void
-Layout::relative_to(char *buf, size_t bufsz, const char *dir, const char *file)
+Layout::relative_to(char *buf, size_t bufsz, ts::string_view dir, 
ts::string_view file)
 {
   char path[PATH_NAME_MAX];
 
-  if (ink_filepath_merge(path, PATH_NAME_MAX, dir, file, 
INK_FILEPATH_TRUENAME)) {
-    int err = errno;
-    // Log error
-    if (err == EACCES) {
-      ink_error("Cannot merge path '%s' above the root '%s'\n", file, dir);
-    } else if (err == E2BIG) {
-      ink_error("Exceeding file name length limit of %d characters\n", 
PATH_NAME_MAX);
-    } else {
-      // TODO: Make some pretty errors.
-      ink_error("Cannot merge '%s' with '%s' error=%d\n", file, dir, err);
-    }
-    return;
-  }
+  _relative(path, PATH_NAME_MAX, dir, file);
   size_t path_len = strlen(path) + 1;
   if (path_len > bufsz) {
-    ink_error("Provided buffer is too small: %zu, required %zu\n", bufsz, 
path_len);
+    ink_fatal("Provided buffer is too small: %zu, required %zu\n", bufsz, 
path_len);
   } else {
     ink_strlcpy(buf, path, bufsz);
   }
 }
 
-Layout::Layout(const char *_prefix)
+Layout::Layout(ts::string_view const _prefix)
 {
-  if (_prefix) {
-    prefix = ats_strdup(_prefix);
+  if (_prefix.size() != 0) {
+    prefix.assign(_prefix.data(), _prefix.size());
   } else {
-    char *env_path;
-    char path[PATH_NAME_MAX];
+    std::string path;
     int len;
-
-    if ((env_path = getenv("TS_ROOT"))) {
-      len = strlen(env_path);
+    if (getenv("TS_ROOT") != nullptr) {
+      std::string env_path(getenv("TS_ROOT"));
+      len = env_path.size();
       if ((len + 1) > PATH_NAME_MAX) {
-        ink_error("TS_ROOT environment variable is too big: %d, max %d\n", 
len, PATH_NAME_MAX - 1);
-        return;
+        ink_fatal("TS_ROOT environment variable is too big: %d, max %d\n", 
len, PATH_NAME_MAX - 1);
       }
-      ink_strlcpy(path, env_path, sizeof(path));
-      while (len > 1 && path[len - 1] == '/') {
-        path[len - 1] = '\0';
-        --len;
+      path = env_path;
+      while (path.back() == '/') {
+        path.pop_back();
       }
     } else {
       // Use compile time --prefix
-      ink_strlcpy(path, TS_BUILD_PREFIX, sizeof(path));
+      path = TS_BUILD_PREFIX;
     }
-
-    prefix = ats_strdup(path);
+    prefix = path;
   }
   exec_prefix   = layout_relative(prefix, TS_BUILD_EXEC_PREFIX);
   bindir        = layout_relative(prefix, TS_BUILD_BINDIR);
@@ -188,19 +149,4 @@ Layout::Layout(const char *_prefix)
 
 Layout::~Layout()
 {
-  ats_free(prefix);
-  ats_free(exec_prefix);
-  ats_free(bindir);
-  ats_free(sbindir);
-  ats_free(sysconfdir);
-  ats_free(datadir);
-  ats_free(includedir);
-  ats_free(libdir);
-  ats_free(libexecdir);
-  ats_free(localstatedir);
-  ats_free(runtimedir);
-  ats_free(logdir);
-  ats_free(mandir);
-  ats_free(infodir);
-  ats_free(cachedir);
 }
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 2b9b7e2..734c6ba 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -252,8 +252,8 @@ test_tslib_CPPFLAGS = $(AM_CPPFLAGS)\
 test_tslib_LDADD = libtsutil.la
 test_tslib_SOURCES = \
        unit-tests/main.cpp \
-       unit-tests/string_view.cpp \
-       unit-tests/test_IpMap.cc 
+       unit-tests/test_IpMap.cc \
+       unit-tests/test_layout.cpp
 
 CompileParseRules_SOURCES = CompileParseRules.cc
 
diff --git a/lib/ts/ink_memory.h b/lib/ts/ink_memory.h
index 8968fa8..f8aa037 100644
--- a/lib/ts/ink_memory.h
+++ b/lib/ts/ink_memory.h
@@ -133,6 +133,16 @@ static inline size_t __attribute__((const)) 
ats_pagesize(void)
 char *_xstrdup(const char *str, int length, const char *path);
 
 #define ats_strdup(p) _xstrdup((p), -1, nullptr)
+
+// this is to help with migration to a std::string issue with older code that
+// expects char* being copied. As more code moves to std::string, this can be
+// removed to avoid these extra copies.
+inline char *
+ats_stringdup(std::string const &p)
+{
+  return p.empty() ? nullptr : _xstrdup(p.c_str(), p.size(), nullptr);
+}
+
 #define ats_strndup(p, n) _xstrdup((p), n, nullptr)
 
 #ifdef __cplusplus
diff --git a/lib/ts/unit-tests/test_layout.cpp 
b/lib/ts/unit-tests/test_layout.cpp
new file mode 100644
index 0000000..59facae
--- /dev/null
+++ b/lib/ts/unit-tests/test_layout.cpp
@@ -0,0 +1,89 @@
+/** @file
+  Test file for layout structure
+  @section license License
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "catch.hpp"
+
+#include "ts/I_Layout.h"
+#include "ts/ink_platform.h"
+
+std::string
+append_slash(const char *path)
+{
+  std::string ret(path);
+  if (ret.back() != '/')
+    ret.append("/");
+  return ret;
+}
+
+// test cases: [constructor], [env_constructor], [create], [relative], 
[relative_to], [update_sysconfdir]
+// ======= test for layout ========
+
+TEST_CASE("constructor test", "[constructor]")
+{
+  Layout layout;
+  // test for constructor
+  REQUIRE(layout.prefix == TS_BUILD_PREFIX);
+  REQUIRE(layout.sysconfdir == layout.relative(TS_BUILD_SYSCONFDIR));
+}
+
+TEST_CASE("environment variable constructor test", "[env_constructor]")
+{
+  std::string newpath = append_slash(TS_BUILD_PREFIX) + "env";
+  setenv("TS_ROOT", newpath.c_str(), true);
+
+  Layout layout;
+  REQUIRE(layout.prefix == newpath);
+  REQUIRE(layout.sysconfdir == layout.relative_to(newpath, 
TS_BUILD_SYSCONFDIR));
+  unsetenv("TS_ROOT");
+}
+
+TEST_CASE("layout create test", "[create]")
+{
+  Layout::create();
+  REQUIRE(Layout::get()->prefix == TS_BUILD_PREFIX);
+  REQUIRE(Layout::get()->sysconfdir == 
Layout::get()->relative(TS_BUILD_SYSCONFDIR));
+}
+
+// tests below based on the created layout
+TEST_CASE("relative test", "[relative]")
+{
+  // relative (1 argument)
+  ts::string_view sv("file");
+  std::string str1 = append_slash(TS_BUILD_PREFIX) + "file";
+  REQUIRE(Layout::get()->relative(sv) == str1);
+}
+
+TEST_CASE("relative to test", "[relative_to]")
+{
+  // relative to (2 parameters)
+  std::string str1 = append_slash(TS_BUILD_PREFIX) + "file";
+  REQUIRE(Layout::relative_to(Layout::get()->prefix, "file") == str1);
+
+  // relative to (4 parameters)
+  char config_file[PATH_NAME_MAX];
+  Layout::relative_to(config_file, sizeof(config_file), 
Layout::get()->sysconfdir, "records.config");
+  std::string a = Layout::relative_to(Layout::get()->sysconfdir, 
"records.config");
+  std::string b = config_file;
+  REQUIRE(a == b);
+}
+
+TEST_CASE("update_sysconfdir test", "[update_sysconfdir]")
+{
+  Layout::get()->update_sysconfdir("/abc");
+  REQUIRE(Layout::get()->sysconfdir == "/abc");
+}
diff --git a/mgmt/Alarms.cc b/mgmt/Alarms.cc
index 6460fb3..d9e8561 100644
--- a/mgmt/Alarms.cc
+++ b/mgmt/Alarms.cc
@@ -72,7 +72,7 @@ alarm_script_dir()
     return path;
   }
 
-  return RecConfigReadBinDir();
+  return ats_stringdup(RecConfigReadBinDir());
 }
 
 Alarms::Alarms()
diff --git a/mgmt/FileManager.cc b/mgmt/FileManager.cc
index 1953ff3..8b4a190 100644
--- a/mgmt/FileManager.cc
+++ b/mgmt/FileManager.cc
@@ -593,7 +593,7 @@ FileManager::WalkSnaps(ExpandingArray *snapList)
   MFresult r;
 
   // Make sure managedDir is the latest from proxy.config.snapshot_dir.
-  this->managedDir = RecConfigReadSnapshotDir();
+  this->managedDir = ats_stringdup(RecConfigReadSnapshotDir());
 
   ink_mutex_acquire(&accessLock);
 
diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
index 0fea99b..73285ab 100644
--- a/mgmt/LocalManager.cc
+++ b/mgmt/LocalManager.cc
@@ -150,9 +150,9 @@ LocalManager::processRunning()
 LocalManager::LocalManager(bool proxy_on) : BaseManager(), run_proxy(proxy_on)
 {
   bool found;
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str bindir(RecConfigReadBinDir());
-  ats_scoped_str sysconfdir(RecConfigReadConfigDir());
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string bindir(RecConfigReadBinDir());
+  std::string sysconfdir(RecConfigReadConfigDir());
 
   manager_started_at = time(nullptr);
 
@@ -168,8 +168,8 @@ LocalManager::LocalManager(bool proxy_on) : BaseManager(), 
run_proxy(proxy_on)
   // Get the default IP binding values.
   RecHttpLoadIp("proxy.local.incoming_ip_to_bind", m_inbound_ip4, 
m_inbound_ip6);
 
-  if (access(sysconfdir, R_OK) == -1) {
-    mgmt_log("[LocalManager::LocalManager] unable to access() directory '%s': 
%d, %s\n", (const char *)sysconfdir, errno,
+  if (access(sysconfdir.c_str(), R_OK) == -1) {
+    mgmt_log("[LocalManager::LocalManager] unable to access() directory '%s': 
%d, %s\n", sysconfdir.c_str(), errno,
              strerror(errno));
     mgmt_fatal(0, "[LocalManager::LocalManager] please set the 'TS_ROOT' 
environment variable\n");
   }
@@ -206,7 +206,7 @@ LocalManager::LocalManager(bool proxy_on) : BaseManager(), 
run_proxy(proxy_on)
   env_prep                     = REC_readString("proxy.config.env_prep", 
&found);
 
   // Calculate proxy_binary from the absolute bin_path
-  absolute_proxy_binary = Layout::relative_to(bindir, proxy_binary);
+  absolute_proxy_binary = ats_stringdup(Layout::relative_to(bindir, 
proxy_binary));
 
   // coverity[fs_check_call]
   if (access(absolute_proxy_binary, R_OK | X_OK) == -1) {
@@ -240,8 +240,8 @@ LocalManager::initAlarm()
 void
 LocalManager::initMgmtProcessServer()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str sockpath(Layout::relative_to(rundir, LM_CONNECTION_SERVER));
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string sockpath(Layout::relative_to(rundir, LM_CONNECTION_SERVER));
   mode_t oldmask = umask(0);
 
 #if TS_HAS_WCCP
@@ -251,9 +251,9 @@ LocalManager::initMgmtProcessServer()
   }
 #endif
 
-  process_server_sockfd = bind_unix_domain_socket(sockpath, 00700);
+  process_server_sockfd = bind_unix_domain_socket(sockpath.c_str(), 00700);
   if (process_server_sockfd == -1) {
-    mgmt_fatal(errno, "[LocalManager::initMgmtProcessServer] failed to bind 
socket at %s\n", (const char *)sockpath);
+    mgmt_fatal(errno, "[LocalManager::initMgmtProcessServer] failed to bind 
socket at %s\n", sockpath.c_str());
   }
 
   umask(oldmask);
@@ -791,9 +791,9 @@ LocalManager::startProxy(const char *onetime_options)
       int res;
 
       char env_prep_bin[MAXPATHLEN];
-      ats_scoped_str bindir(RecConfigReadBinDir());
+      std::string bindir(RecConfigReadBinDir());
 
-      ink_filepath_make(env_prep_bin, sizeof(env_prep_bin), bindir, env_prep);
+      ink_filepath_make(env_prep_bin, sizeof(env_prep_bin), bindir.c_str(), 
env_prep);
       res = execl(env_prep_bin, env_prep_bin, (char *)nullptr);
       _exit(res);
     }
diff --git a/mgmt/ProcessManager.cc b/mgmt/ProcessManager.cc
index 663f206..bdd90af 100644
--- a/mgmt/ProcessManager.cc
+++ b/mgmt/ProcessManager.cc
@@ -293,8 +293,8 @@ ProcessManager::processSignalQueue()
 void
 ProcessManager::initLMConnection()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str sockpath(Layout::relative_to(rundir, LM_CONNECTION_SERVER));
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string sockpath(Layout::relative_to(rundir, LM_CONNECTION_SERVER));
 
   MgmtMessageHdr *mh_full;
   int data_len;
@@ -306,7 +306,7 @@ ProcessManager::initLMConnection()
   memset((char *)&serv_addr, 0, sizeof(serv_addr));
   serv_addr.sun_family = AF_UNIX;
 
-  ink_strlcpy(serv_addr.sun_path, sockpath, sizeof(serv_addr.sun_path));
+  ink_strlcpy(serv_addr.sun_path, sockpath.c_str(), 
sizeof(serv_addr.sun_path));
 #if defined(darwin) || defined(freebsd)
   servlen = sizeof(sockaddr_un);
 #else
@@ -314,7 +314,7 @@ ProcessManager::initLMConnection()
 #endif
 
   if ((local_manager_sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
-    Fatal("Unable to create socket '%s': %s", (const char *)sockpath, 
strerror(errno));
+    Fatal("Unable to create socket '%s': %s", sockpath.c_str(), 
strerror(errno));
   }
 
   if (fcntl(local_manager_sockfd, F_SETFD, FD_CLOEXEC) < 0) {
@@ -322,7 +322,7 @@ ProcessManager::initLMConnection()
   }
 
   if ((connect(local_manager_sockfd, (struct sockaddr *)&serv_addr, servlen)) 
< 0) {
-    Fatal("failed to connect management socket '%s': %s", (const char 
*)sockpath, strerror(errno));
+    Fatal("failed to connect management socket '%s': %s", sockpath.c_str(), 
strerror(errno));
   }
 
   data_len          = sizeof(pid_t);
diff --git a/mgmt/Rollback.cc b/mgmt/Rollback.cc
index cd37dce..e7e71db 100644
--- a/mgmt/Rollback.cc
+++ b/mgmt/Rollback.cc
@@ -233,8 +233,8 @@ Rollback::createPathStr(version_t version)
 {
   int bufSize  = 0;
   char *buffer = nullptr;
-  ats_scoped_str sysconfdir(RecConfigReadConfigDir());
-  bufSize = strlen(sysconfdir) + fileNameLen + MAX_VERSION_DIGITS + 1;
+  std::string sysconfdir(RecConfigReadConfigDir());
+  bufSize = sysconfdir.size() + fileNameLen + MAX_VERSION_DIGITS + 1;
   buffer  = (char *)ats_malloc(bufSize);
   Layout::get()->relative_to(buffer, bufSize, sysconfdir, fileName);
   if (version != ACTIVE_VERSION) {
diff --git a/mgmt/api/CoreAPIRemote.cc b/mgmt/api/CoreAPIRemote.cc
index 73b26ce..1f012d5 100644
--- a/mgmt/api/CoreAPIRemote.cc
+++ b/mgmt/api/CoreAPIRemote.cc
@@ -196,7 +196,7 @@ Init(const char *socket_path, TSInitOptionT options)
   // libraries. The caller has to pass down the right socket path :(
   if (!socket_path) {
     Layout::create();
-    socket_path = Layout::get()->runtimedir;
+    socket_path = Layout::get()->runtimedir.c_str();
   }
 
   // store socket_path
diff --git a/mgmt/api/NetworkUtilsRemote.cc b/mgmt/api/NetworkUtilsRemote.cc
index 740ae46..d0c7152 100644
--- a/mgmt/api/NetworkUtilsRemote.cc
+++ b/mgmt/api/NetworkUtilsRemote.cc
@@ -57,8 +57,8 @@ set_socket_paths(const char *path)
   // construct paths based on user input
   // form by replacing "mgmtapi.sock" with "eventapi.sock"
   if (path) {
-    main_socket_path  = Layout::relative_to(path, MGMTAPI_MGMT_SOCKET_NAME);
-    event_socket_path = Layout::relative_to(path, MGMTAPI_EVENT_SOCKET_NAME);
+    main_socket_path  = ats_stringdup(Layout::relative_to(path, 
MGMTAPI_MGMT_SOCKET_NAME));
+    event_socket_path = ats_stringdup(Layout::relative_to(path, 
MGMTAPI_EVENT_SOCKET_NAME));
   } else {
     main_socket_path  = nullptr;
     event_socket_path = nullptr;
diff --git a/proxy/Crash.cc b/proxy/Crash.cc
index b99abde..366d5fd 100644
--- a/proxy/Crash.cc
+++ b/proxy/Crash.cc
@@ -40,7 +40,7 @@ static char *
 create_logger_path()
 {
   RecString name;
-  ats_scoped_str bindir;
+  std::string bindir;
   ats_scoped_str fullpath;
 
   if (RecGetRecordString_Xmalloc("proxy.config.crash_log_helper", &name) != 
REC_ERR_OKAY) {
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index b4614b0..644ca53 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -1769,21 +1769,22 @@ TShrtime()
 const char *
 TSInstallDirGet(void)
 {
-  return Layout::get()->prefix;
+  static std::string prefix = Layout::get()->prefix;
+  return prefix.c_str();
 }
 
 const char *
 TSConfigDirGet(void)
 {
-  static const char *sysconfdir = RecConfigReadConfigDir();
-  return sysconfdir;
+  static std::string sysconfdir = RecConfigReadConfigDir();
+  return sysconfdir.c_str();
 }
 
 const char *
 TSRuntimeDirGet(void)
 {
-  static const char *runtimedir = RecConfigReadRuntimeDir();
-  return runtimedir;
+  static std::string runtimedir = RecConfigReadRuntimeDir();
+  return runtimedir.c_str();
 }
 
 const char *
@@ -1811,9 +1812,8 @@ TSTrafficServerVersionGetPatch()
 const char *
 TSPluginDirGet(void)
 {
-  static const char *path = RecConfigReadPluginDir();
-
-  return path;
+  static std::string path = RecConfigReadPluginDir();
+  return path.c_str();
 }
 
 ////////////////////////////////////////////////////////////////////
diff --git a/proxy/Main.cc b/proxy/Main.cc
index d257a5e..5be69e4 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -508,19 +508,19 @@ init_system()
 static void
 check_lockfile()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str lockfile;
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string lockfile;
   pid_t holding_pid;
   int err;
 
   lockfile = Layout::relative_to(rundir, SERVER_LOCK);
 
-  Lockfile server_lockfile(lockfile);
+  Lockfile server_lockfile(lockfile.c_str());
   err = server_lockfile.Get(&holding_pid);
 
   if (err != 1) {
     char *reason = strerror(-err);
-    fprintf(stderr, "WARNING: Can't acquire lockfile '%s'", (const char 
*)lockfile);
+    fprintf(stderr, "WARNING: Can't acquire lockfile '%s'", lockfile.c_str());
 
     if ((err == 0) && (holding_pid != -1)) {
       fprintf(stderr, " (Lock file held by process ID %ld)\n", 
(long)holding_pid);
@@ -538,17 +538,17 @@ check_lockfile()
 static void
 check_config_directories()
 {
-  ats_scoped_str rundir(RecConfigReadRuntimeDir());
-  ats_scoped_str sysconfdir(RecConfigReadConfigDir());
+  std::string rundir(RecConfigReadRuntimeDir());
+  std::string sysconfdir(RecConfigReadConfigDir());
 
-  if (access(sysconfdir, R_OK) == -1) {
-    fprintf(stderr, "unable to access() config dir '%s': %d, %s\n", (const 
char *)sysconfdir, errno, strerror(errno));
+  if (access(sysconfdir.c_str(), R_OK) == -1) {
+    fprintf(stderr, "unable to access() config dir '%s': %d, %s\n", 
sysconfdir.c_str(), errno, strerror(errno));
     fprintf(stderr, "please set the 'TS_ROOT' environment variable\n");
     ::exit(1);
   }
 
-  if (access(rundir, R_OK | W_OK) == -1) {
-    fprintf(stderr, "unable to access() local state dir '%s': %d, %s\n", 
(const char *)rundir, errno, strerror(errno));
+  if (access(rundir.c_str(), R_OK | W_OK) == -1) {
+    fprintf(stderr, "unable to access() local state dir '%s': %d, %s\n", 
rundir.c_str(), errno, strerror(errno));
     fprintf(stderr, "please set 'proxy.config.local_state_dir'\n");
     ::exit(1);
   }
@@ -767,12 +767,12 @@ cmd_clear(char *cmd)
   bool c_cache = !strcmp(cmd, "clear_cache");
 
   if (c_all || c_hdb) {
-    ats_scoped_str rundir(RecConfigReadRuntimeDir());
-    ats_scoped_str config(Layout::relative_to(rundir, "hostdb.config"));
+    std::string rundir(RecConfigReadRuntimeDir());
+    std::string config(Layout::relative_to(rundir, "hostdb.config"));
 
     Note("Clearing HostDB Configuration");
-    if (unlink(config) < 0) {
-      Note("unable to unlink %s", (const char *)config);
+    if (unlink(config.c_str()) < 0) {
+      Note("unable to unlink %s", config.c_str());
     }
   }
 
@@ -1355,15 +1355,15 @@ run_RegressionTest()
 static void
 chdir_root()
 {
-  const char *prefix = Layout::get()->prefix;
+  std::string prefix = Layout::get()->prefix;
 
-  if (chdir(prefix) < 0) {
-    fprintf(stderr, "%s: unable to change to root directory \"%s\" [%d 
'%s']\n", appVersionInfo.AppStr, prefix, errno,
+  if (chdir(prefix.c_str()) < 0) {
+    fprintf(stderr, "%s: unable to change to root directory \"%s\" [%d 
'%s']\n", appVersionInfo.AppStr, prefix.c_str(), errno,
             strerror(errno));
     fprintf(stderr, "%s: please correct the path or set the TS_ROOT 
environment variable\n", appVersionInfo.AppStr);
     ::exit(1);
   } else {
-    printf("%s: using root directory '%s'\n", appVersionInfo.AppStr, prefix);
+    printf("%s: using root directory '%s'\n", appVersionInfo.AppStr, 
prefix.c_str());
   }
 }
 
diff --git a/proxy/Plugin.cc b/proxy/Plugin.cc
index 240574b..250edf1 100644
--- a/proxy/Plugin.cc
+++ b/proxy/Plugin.cc
@@ -231,7 +231,7 @@ plugin_init(bool validateOnly)
 
   if (INIT_ONCE) {
     api_init();
-    plugin_dir = RecConfigReadPluginDir();
+    plugin_dir = ats_stringdup(RecConfigReadPluginDir());
     INIT_ONCE  = false;
   }
 
diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc
index b9e3ade..1f889df 100644
--- a/proxy/http/remap/RemapConfig.cc
+++ b/proxy/http/remap/RemapConfig.cc
@@ -337,7 +337,7 @@ parse_include_directive(const char *directive, 
BUILD_TABLE_INFO *bti, char *errb
           continue;
         }
 
-        subpath = Layout::relative_to(path, entrylist[j]->d_name);
+        subpath = Layout::relative_to(path.get(), entrylist[j]->d_name);
 
         if (ink_file_is_directory(subpath)) {
           continue;
diff --git a/proxy/logging/LogConfig.cc b/proxy/logging/LogConfig.cc
index e818c56..61faff1 100644
--- a/proxy/logging/LogConfig.cc
+++ b/proxy/logging/LogConfig.cc
@@ -163,7 +163,7 @@ LogConfig::read_configuration_variables()
   }
 
   ats_free(logfile_dir);
-  logfile_dir = RecConfigReadLogDir();
+  logfile_dir = ats_stringdup(RecConfigReadLogDir());
 
   if (access(logfile_dir, R_OK | W_OK | X_OK) == -1) {
     // Try 'system_root_dir/var/log/trafficserver' directory
diff --git a/proxy/logging/LogStandalone.cc b/proxy/logging/LogStandalone.cc
index 1102c59..d2091b3 100644
--- a/proxy/logging/LogStandalone.cc
+++ b/proxy/logging/LogStandalone.cc
@@ -148,12 +148,12 @@ check_lockfile()
   pid_t holding_pid;
   char *lockfile = nullptr;
 
-  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));
+  if (access(Layout::get()->runtimedir.c_str(), R_OK | W_OK) == -1) {
+    fprintf(stderr, "unable to access() dir'%s': %d, %s\n", 
Layout::get()->runtimedir.c_str(), errno, strerror(errno));
     fprintf(stderr, " please set correct path in env variable TS_ROOT \n");
     ::exit(1);
   }
-  lockfile = Layout::relative_to(Layout::get()->runtimedir, SERVER_LOCK);
+  lockfile = ats_stringdup(Layout::relative_to(Layout::get()->runtimedir, 
SERVER_LOCK));
 
   Lockfile server_lockfile(lockfile);
   err = server_lockfile.Get(&holding_pid);
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index 5efc506..18c914e 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -2442,7 +2442,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
         if (end > start) {
           char *buf;
 
-          buf = ats_strdup(line.substr(start, end).c_str());
+          buf = ats_stringdup(line.substr(start, end));
           if (buf) {
             origin_set->insert(buf);
           }
@@ -2470,7 +2470,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
   // Do the incremental parse of the default squid log.
   if (cl.incremental) {
     // Change directory to the log dir
-    if (chdir(Layout::get()->logdir) < 0) {
+    if (chdir(Layout::get()->logdir.c_str()) < 0) {
       exit_status.set(EXIT_CRITICAL, " can't chdir to ");
       exit_status.append(Layout::get()->logdir);
       my_exit(exit_status);
@@ -2573,7 +2573,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
       last_state.st_ino = stat_buf.st_ino;
 
       // Find the old log file.
-      dirp = opendir(Layout::get()->logdir);
+      dirp = opendir(Layout::get()->logdir.c_str());
       if (nullptr == dirp) {
         exit_status.set(EXIT_WARNING, " can't read log directory");
       } else {

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Reply via email to