This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch 8.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 5d8c69361271af49f5982c9f2c3af32f619c1d3c Author: Xavier Chi <[email protected]> AuthorDate: Wed Jun 6 16:22:55 2018 -0500 Fix multiple issues of traffic_layout and add a readme clang-format (cherry picked from commit a9ad341bb16910124608729539b3e47a998aedb0) --- cmd/traffic_layout/README | 5 +++++ cmd/traffic_layout/engine.cc | 42 +++++++++++++++++++++++++++++---------- cmd/traffic_layout/engine.h | 2 ++ cmd/traffic_layout/file_system.cc | 17 ++++++++-------- lib/ts/runroot.cc | 24 ++++++++++++++++++++++ lib/ts/runroot.h | 2 ++ 6 files changed, 73 insertions(+), 19 deletions(-) diff --git a/cmd/traffic_layout/README b/cmd/traffic_layout/README new file mode 100644 index 0000000..0c65d61 --- /dev/null +++ b/cmd/traffic_layout/README @@ -0,0 +1,5 @@ +traffic_layout is a easy-to-use tool to: +- show the location of various installation paths and resources. +- deal with traffic server runroot. + +For detailed information, please refer to doc/appendices/command-line/traffic_layout.en.rst. diff --git a/cmd/traffic_layout/engine.cc b/cmd/traffic_layout/engine.cc index 5525712..6d42a35 100644 --- a/cmd/traffic_layout/engine.cc +++ b/cmd/traffic_layout/engine.cc @@ -258,7 +258,11 @@ RunrootEngine::sanity_check() path = path_handler(path, run_flag, _argv[0]); if (path.empty()) { - ink_fatal("Path not valild (runroot_path.yml not found)"); + if (!verify_flag) { + ink_fatal("Path not valild (runroot_path.yml not found)"); + } else { + verify_default = true; + } } if (run_flag) { @@ -379,13 +383,13 @@ RunrootEngine::create_runroot() std::cout << "creating runroot - " + ts_runroot << std::endl; // check for existing runroot to use rather than create new one - if (check_file.good()) { + if (!force_flag && check_file.good()) { std::cout << "Using existing runroot...\n" "Please remove the old runroot if new runroot is needed" << std::endl; return; } - if (!check_parent_path(ts_runroot).empty()) { + if (!force_flag && !check_parent_path(ts_runroot).empty()) { ink_fatal("Cannot create runroot inside another runroot"); } @@ -454,7 +458,12 @@ RunrootEngine::copy_runroot(const std::string &original_root, const std::string // don't copy the prefix, mandir and localstatedir if (it.first != "exec_prefix" && it.first != "localstatedir" && it.first != "mandir") { if (!copy_directory(old_path, new_path, it.first)) { - ink_warning("Copy failed for '%s' - %s", it.first.c_str(), strerror(errno)); + ink_warning("Unable to copy '%s' - %s", it.first.c_str(), strerror(errno)); + ink_notice("Creating '%s': %s", it.first.c_str(), new_path.c_str()); + // if copy failed for certain directory, we create it in runroot + if (!create_directory(new_path)) { + ink_warning("Unable to create '%s' - %s", it.first.c_str(), strerror(errno)); + } } } } @@ -541,8 +550,8 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType &permission_map, RunrootMap struct stat stat_buffer; if (stat(path.c_str(), &stat_buffer) < 0) { - ink_error("unable to stat() destination path %s: %s", path.c_str(), strerror(errno)); - exit(70); + ink_warning("unable to stat() destination path %s: %s", path.c_str(), strerror(errno)); + continue; } if (usergroup == "owner") { @@ -563,6 +572,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType &permission_map, RunrootMap if (chmod(path.c_str(), stat_buffer.st_mode | read_permission) < 0) { ink_warning("Unable to change file mode on %s: %s", path.c_str(), strerror(errno)); } + std::cout << "Read permission fixed for '" + name + "': " + path << std::endl; } if (name == "localstatedir" || name == "logdir" || name == "runtimedir" || name == "cachedir") { // write @@ -570,6 +580,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType &permission_map, RunrootMap if (chmod(path.c_str(), stat_buffer.st_mode | read_permission | write_permission) < 0) { ink_warning("Unable to change file mode on %s: %s", path.c_str(), strerror(errno)); } + std::cout << "Write permission fixed for '" + name + "': " + path << std::endl; } } if (name == "bindir" || name == "sbindir" || name == "libdir" || name == "libexecdir") { @@ -578,6 +589,7 @@ fix_runroot(RunrootMapType &path_map, RunrootMapType &permission_map, RunrootMap if (chmod(path.c_str(), stat_buffer.st_mode | read_permission | execute_permission) < 0) { ink_warning("Unable to change file mode on %s: %s", path.c_str(), strerror(errno)); } + std::cout << "Execute permission fixed for '" + name + "': " + path << std::endl; } } } @@ -599,15 +611,15 @@ set_permission(std::vector<std::string> &dir_vector, RunrootMapType &path_map, R // set up permission map for all permissions for (uint i = 0; i < dir_vector.size(); i++) { std::string name = dir_vector[i]; - std::string value = path_map[dir_vector[i]]; + std::string value = path_map[name]; if (name == "prefix" || name == "exec_prefix") { continue; } if (stat(value.c_str(), &stat_buffer) < 0) { - ink_error("unable to stat() destination path %s: %s", value.c_str(), strerror(errno)); - exit(70); + ink_warning("unable to stat() destination path %s: %s", value.c_str(), strerror(errno)); + continue; } int path_gid = int(stat_buffer.st_gid); int path_uid = int(stat_buffer.st_uid); @@ -658,7 +670,15 @@ RunrootEngine::verify_runroot() { std::cout << "trafficserver user: " << TS_PKGSYSUSER << std::endl << std::endl; - RunrootMapType path_map = runroot_map(path); + // put paths from yaml file or default paths to path_map + RunrootMapType path_map; + if (verify_default) { + path_map = runroot_map_default(); + std::cout << "Verifying default build ..." << std::endl; + } else { + path_map = runroot_map(path); + } + RunrootMapType permission_map; // contains rwx bits RunrootMapType usergroup_map; // map: owner, group, others @@ -691,4 +711,4 @@ RunrootEngine::verify_runroot() output_execute_permission(permission); } } -} \ No newline at end of file +} diff --git a/cmd/traffic_layout/engine.h b/cmd/traffic_layout/engine.h index 6af158f..241ba59 100644 --- a/cmd/traffic_layout/engine.h +++ b/cmd/traffic_layout/engine.h @@ -66,6 +66,8 @@ struct RunrootEngine { bool abs_flag = false; bool verify_flag = false; bool fix_flag = false; + // verify the default layout or not + bool verify_default = false; // for parsing int command_num = 0; diff --git a/cmd/traffic_layout/file_system.cc b/cmd/traffic_layout/file_system.cc index e28a415..7706a25 100644 --- a/cmd/traffic_layout/file_system.cc +++ b/cmd/traffic_layout/file_system.cc @@ -258,15 +258,16 @@ ts_copy_function(const char *src_path, const struct stat *sb, int flag) if (errno != EEXIST) { ink_warning("failed to create hard link - %s", strerror(errno)); } + } else { + return 0; } - } else { - // for normal other files - std::ifstream src(src_path, std::ios::binary); - std::ofstream dst(dst_path, std::ios::binary); - dst << src.rdbuf(); - if (chmod(dst_path.c_str(), sb->st_mode) == -1) { - ink_warning("failed chomd the destination path: %s", strerror(errno)); - } + } + // for normal other files + std::ifstream src(src_path, std::ios::binary); + std::ofstream dst(dst_path, std::ios::binary); + dst << src.rdbuf(); + if (chmod(dst_path.c_str(), sb->st_mode) == -1) { + ink_warning("failed chomd the destination path: %s", strerror(errno)); } } return 0; diff --git a/lib/ts/runroot.cc b/lib/ts/runroot.cc index 0cdb9ca..ac85cd6 100644 --- a/lib/ts/runroot.cc +++ b/lib/ts/runroot.cc @@ -182,6 +182,30 @@ runroot_handler(const char **argv, bool json) return; } +// return a map of all path with default layout +std::unordered_map<std::string, std::string> +runroot_map_default() +{ + std::unordered_map<std::string, std::string> map; + + map["prefix"] = Layout::get()->prefix; + map["exec_prefix"] = Layout::get()->exec_prefix; + map["bindir"] = Layout::get()->bindir; + map["sbindir"] = Layout::get()->sbindir; + map["sysconfdir"] = Layout::get()->sysconfdir; + map["datadir"] = Layout::get()->datadir; + map["includedir"] = Layout::get()->includedir; + map["libdir"] = Layout::get()->libdir; + map["libexecdir"] = Layout::get()->libexecdir; + map["localstatedir"] = Layout::get()->localstatedir; + map["runtimedir"] = Layout::get()->runtimedir; + map["logdir"] = Layout::get()->logdir; + // mandir is not needed for runroot + map["cachedir"] = Layout::get()->cachedir; + + return map; +} + // return a map of all path in runroot_path.yml std::unordered_map<std::string, std::string> runroot_map(const std::string &prefix) diff --git a/lib/ts/runroot.h b/lib/ts/runroot.h index 23a1aa5..be3852a 100644 --- a/lib/ts/runroot.h +++ b/lib/ts/runroot.h @@ -35,6 +35,8 @@ std::string check_parent_path(const std::string &path); void runroot_handler(const char **argv, bool json = false); +// get a map from default layout +std::unordered_map<std::string, std::string> runroot_map_default(); // get runroot map from yaml path and prefix std::unordered_map<std::string, std::string> runroot_map(const std::string &prefix); -- To stop receiving notification emails like this one, please contact [email protected].
