TS-2401: Add RecConfigReadLogDir() to wrap proxy.config.log.logfile_dir access
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/a1162d83 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/a1162d83 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/a1162d83 Branch: refs/heads/master Commit: a1162d8368a3f6a3401a31983ac90181f5a11782 Parents: b6288c4 Author: James Peach <[email protected]> Authored: Tue Dec 3 13:25:11 2013 -0800 Committer: James Peach <[email protected]> Committed: Thu Dec 5 20:33:49 2013 -0800 ---------------------------------------------------------------------- lib/records/I_RecCore.h | 4 ++++ lib/records/RecCore.cc | 17 +++++++++++++++++ proxy/InkAPITest.cc | 5 ++--- proxy/logging/LogConfig.cc | 12 ++---------- proxy/shared/DiagsConfig.cc | 9 +-------- 5 files changed, 26 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a1162d83/lib/records/I_RecCore.h ---------------------------------------------------------------------- diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h index 8462752..39d2e9d 100644 --- a/lib/records/I_RecCore.h +++ b/lib/records/I_RecCore.h @@ -53,6 +53,10 @@ char * RecConfigReadRuntimeDir(); // MUST release the result with ats_free(). char * 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(); + // Return a copy of a configuration file that is relative to sysconfdir. The relative path to the configuration // file is specified in the configuration variable named by "file_variable". If the configuration variable has no // value, NULL is returned. The caller MUST release the result with ats_free(). http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a1162d83/lib/records/RecCore.cc ---------------------------------------------------------------------- diff --git a/lib/records/RecCore.cc b/lib/records/RecCore.cc index 6c17cc9..96cddfc 100644 --- a/lib/records/RecCore.cc +++ b/lib/records/RecCore.cc @@ -1071,6 +1071,23 @@ RecConfigReadRuntimeDir() } //------------------------------------------------------------------------- +// RecConfigReadLogDir +//------------------------------------------------------------------------- +char * +RecConfigReadLogDir() +{ + char buf[PATH_NAME_MAX + 1]; + + buf[0] = '\0'; + RecGetRecordString("proxy.config.log.logfile_dir", buf, PATH_NAME_MAX); + if (strlen(buf) > 0) { + return Layout::get()->relative(buf); + } else { + return ats_strdup(Layout::get()->logdir); + } +} + +//------------------------------------------------------------------------- // RecConfigReadSnapshotDir. //------------------------------------------------------------------------- char * http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a1162d83/proxy/InkAPITest.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc index 3e0ce3a..8f97a88 100644 --- a/proxy/InkAPITest.cc +++ b/proxy/InkAPITest.cc @@ -5340,10 +5340,9 @@ REGRESSION_TEST(SDK_API_TSTextLog) (RegressionTest * test, int /* atype ATS_UNUS /* Generate a random log file name, so if we run the test several times, we won't use the same log file name. */ - char *tmp = REC_ConfigReadString("proxy.config.log.logfile_dir"); + xptr<char> tmp(RecConfigReadLogDir()); snprintf(logname, sizeof(logname), "RegressionTestLog%d.log", (int) getpid()); - snprintf(fullpath_logname, sizeof(fullpath_logname), "%s/%s", tmp, logname); - // ats_free(tmp); + snprintf(fullpath_logname, sizeof(fullpath_logname), "%s/%s", (const char *)tmp, logname); unlink(fullpath_logname); retVal = TSTextLogObjectCreate(logname, TS_LOG_MODE_ADD_TIMESTAMP, &log); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a1162d83/proxy/logging/LogConfig.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogConfig.cc b/proxy/logging/LogConfig.cc index 5810e8f..133ea21 100644 --- a/proxy/logging/LogConfig.cc +++ b/proxy/logging/LogConfig.cc @@ -240,16 +240,8 @@ LogConfig::read_configuration_variables() hostname = ptr; } - ptr = REC_ConfigReadString("proxy.config.log.logfile_dir"); - if (ptr != NULL) { - ats_free(logfile_dir); - // Make it relative from Layout - logfile_dir = Layout::get()->relative(ptr); - ats_free(ptr); - } else { - ats_free(logfile_dir); - logfile_dir = ats_strdup(Layout::get()->logdir); - } + ats_free(logfile_dir); + logfile_dir = RecConfigReadLogDir(); if (access(logfile_dir, R_OK | W_OK | X_OK) == -1) { // Try 'system_root_dir/var/log/trafficserver' directory http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a1162d83/proxy/shared/DiagsConfig.cc ---------------------------------------------------------------------- diff --git a/proxy/shared/DiagsConfig.cc b/proxy/shared/DiagsConfig.cc index 27ec46b..3cb6a3d 100644 --- a/proxy/shared/DiagsConfig.cc +++ b/proxy/shared/DiagsConfig.cc @@ -309,14 +309,7 @@ DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records) // Open the diagnostics log. If proxy.config.log.logfile_dir is set use that, otherwise fall // back to the configured log directory. - diags_logpath[0] = '\0'; - REC_ReadConfigString(diags_logpath, "proxy.config.log.logfile_dir", PATH_NAME_MAX); - if (strlen(diags_logpath) > 0) { - logpath = Layout::get()->relative(diags_logpath); - } else { - logpath = ats_strdup(Layout::get()->logdir); - } - + logpath = RecConfigReadLogDir(); if (access(logpath, W_OK | R_OK) == -1) { fprintf(stderr, "unable to access log directory '%s': %d, %s\n", (const char *)logpath, errno, strerror(errno));
