You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/01/12 16:03:47 UTC
[trafficserver] 06/09: Fix traffic_layout to not add messages to
--json
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0f1bfdd45acc139e52e4c5dff950ef4116c3daf7
Author: Jason Kenny <dr...@live.com>
AuthorDate: Mon Aug 14 11:21:17 2017 -0500
Fix traffic_layout to not add messages to --json
Fix issues with possible memory leak with realpath
fix issue with realpath returning NULL
Fix issue #2367 realpath error could cause crash
coverity issues 1379612 1379613 1379614 1379615 1379616 1379617 1379618 1379619
Clang format
(cherry picked from commit c746df2d6936e670caf0ffb8a450a548ee1de9bb)
---
cmd/traffic_layout/traffic_layout.cc | 2 +-
lib/ts/Layout.cc | 2 --
lib/ts/runroot.cc | 38 +++++++++++++++++++-----------------
3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/cmd/traffic_layout/traffic_layout.cc b/cmd/traffic_layout/traffic_layout.cc
index f22fb57..eb7a452 100644
--- a/cmd/traffic_layout/traffic_layout.cc
+++ b/cmd/traffic_layout/traffic_layout.cc
@@ -178,7 +178,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
// Process command line arguments and dump into variables
process_args(&appVersionInfo, argument_descriptions, countof(argument_descriptions), argv);
- runroot_handler(argv);
+ runroot_handler(argv, 0 != cl.json);
if (cl.features) {
produce_features(0 != cl.json);
diff --git a/lib/ts/Layout.cc b/lib/ts/Layout.cc
index 5abbffc..da52989 100644
--- a/lib/ts/Layout.cc
+++ b/lib/ts/Layout.cc
@@ -29,7 +29,6 @@
#include "ts/I_Layout.h"
#include <fstream>
-#include <iostream>
#include <unordered_map>
static Layout *layout = nullptr;
@@ -125,7 +124,6 @@ Layout::check_runroot()
if ((len + 1) > PATH_NAME_MAX) {
ink_fatal("TS_RUNROOT environment variable is too big: %d, max %d\n", len, PATH_NAME_MAX - 1);
}
- std::cout << "TS_RUNROOT initiated..." << std::endl;
std::ifstream file;
if (env_path.back() != '/') {
env_path.append("/");
diff --git a/lib/ts/runroot.cc b/lib/ts/runroot.cc
index 785e7e5..c6261c4 100644
--- a/lib/ts/runroot.cc
+++ b/lib/ts/runroot.cc
@@ -41,7 +41,6 @@ datadir, libexecdir, libdir, runtimedir, infodir, cachedir.
#include <vector>
#include <string>
-#include <iostream>
#include <fstream>
#include <set>
#include <unistd.h>
@@ -51,7 +50,7 @@ datadir, libexecdir, libdir, runtimedir, infodir, cachedir.
// the function for the checking of the yaml file in parent path
// if found return the parent path containing the yaml file
static std::string
-check_parent_path(const std::string &path)
+check_parent_path(const std::string &path, bool json = false)
{
std::string whole_path = path;
if (whole_path.back() == '/')
@@ -63,7 +62,8 @@ check_parent_path(const std::string &path)
std::ifstream parent_check_file;
parent_check_file.open(parent_yaml_path);
if (parent_check_file.good()) {
- std::cout << "using parent of bin/current working dir" << std::endl;
+ if (!json)
+ ink_notice("using parent of bin/current working dir");
return whole_path;
}
}
@@ -72,7 +72,7 @@ check_parent_path(const std::string &path)
// handler for ts runroot
void
-runroot_handler(const char **argv)
+runroot_handler(const char **argv, bool json = false)
{
std::string command = {};
std::string arg = {};
@@ -102,31 +102,33 @@ runroot_handler(const char **argv)
std::string yaml_path = path + "runroot_path.yaml";
yaml_checkfile.open(yaml_path);
if (yaml_checkfile.good()) {
- std::cout << "using command line path as RUNROOT" << std::endl;
+ if (!json)
+ ink_notice("using command line path as RUNROOT");
setenv("USING_RUNROOT", path.c_str(), true);
return;
} else {
- ink_warning("bad RUNROOT");
+ if (!json)
+ ink_warning("bad RUNROOT");
}
}
// 2. argv provided invalid/no yaml file, then check env variable
if (getenv("TS_RUNROOT") != nullptr) {
setenv("USING_RUNROOT", getenv("TS_RUNROOT"), true);
- std::cout << "using the environment variable TS_RUNROOT" << std::endl;
+ if (!json)
+ ink_notice("using the environment variable TS_RUNROOT");
return;
}
// 3. find parent path of bin/pwd to check
- char cwd[MAX_CWD_LEN];
- getcwd(cwd, sizeof(cwd));
- std::string RealBinPath = realpath(argv[0], nullptr); // bin path
-
- std::vector<std::string> TwoPath = {RealBinPath, cwd};
- for (auto it : TwoPath) {
- std::string path = check_parent_path(it);
- if (!path.empty()) {
- setenv("USING_RUNROOT", path.c_str(), true);
- return;
+ char cwd[MAX_CWD_LEN] = {0};
+ char RealBinPath[PATH_MAX] = {0};
+ if ((argv[0] != nullptr) && (getcwd(cwd, sizeof(cwd)) != nullptr) && (realpath(argv[0], RealBinPath) != nullptr)) {
+ std::vector<std::string> TwoPath = {RealBinPath, cwd};
+ for (auto it : TwoPath) {
+ std::string path = check_parent_path(it);
+ if (!path.empty()) {
+ setenv("USING_RUNROOT", path.c_str(), true);
+ return;
+ }
}
}
- std::cout << "Failed to initialize TS_RUNROOT, using default path..." << std::endl;
}
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.