Repository: trafficserver Updated Branches: refs/heads/master a8d186224 -> f2fc28902
TS-1256: add ink_file_namemax to replace raw pathconf calls Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f2fc2890 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f2fc2890 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f2fc2890 Branch: refs/heads/master Commit: f2fc289026553b57461dc2a5395aefce842839c1 Parents: 34d2200 Author: James Peach <[email protected]> Authored: Mon Nov 3 13:48:03 2014 -0800 Committer: James Peach <[email protected]> Committed: Mon Dec 15 16:43:03 2014 -0800 ---------------------------------------------------------------------- lib/ts/ink_file.cc | 17 +++++++++++++++++ lib/ts/ink_file.h | 3 +++ mgmt/FileManager.cc | 2 +- mgmt/MultiFile.cc | 2 +- mgmt/Rollback.cc | 2 +- mgmt/WebMgmtUtils.cc | 2 +- proxy/logging/LogConfig.cc | 7 +------ 7 files changed, 25 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/lib/ts/ink_file.cc ---------------------------------------------------------------------- diff --git a/lib/ts/ink_file.cc b/lib/ts/ink_file.cc index 5ccff6f..0294482 100644 --- a/lib/ts/ink_file.cc +++ b/lib/ts/ink_file.cc @@ -22,6 +22,8 @@ */ #include "libts.h" +#include <unistd.h> +#include <limits.h> #if HAVE_SYS_STAT_H #include <sys/stat.h> @@ -502,3 +504,18 @@ ink_file_get_geometry(int fd ATS_UNUSED, ink_device_geometry& geometry) return true; } + +size_t +ink_file_namemax(const char * path) +{ + long namemax = pathconf(path, _PC_NAME_MAX); + if (namemax > 0) { + return namemax; + } + +#if defined(NAME_MAX) + return NAME_MAX; +#else + return 255; +#endif +} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/lib/ts/ink_file.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_file.h b/lib/ts/ink_file.h index 1feda36..41f3f96 100644 --- a/lib/ts/ink_file.h +++ b/lib/ts/ink_file.h @@ -118,6 +118,9 @@ struct ink_device_geometry bool ink_file_get_geometry(int fd, ink_device_geometry& geometry); +// Return the value of pathconf(path, _PC_NAME_MAX), or the closest approximation. +size_t ink_file_namemax(const char * path); + // Is the given path "."? static inline bool isdot(const char * path) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/mgmt/FileManager.cc ---------------------------------------------------------------------- diff --git a/mgmt/FileManager.cc b/mgmt/FileManager.cc index 6352e11..1508be3 100644 --- a/mgmt/FileManager.cc +++ b/mgmt/FileManager.cc @@ -411,7 +411,7 @@ FileManager::removeSnap(const char *snapName, const char *snapDir) return SNAP_NOT_FOUND; } - dirEntrySpace = (struct dirent *)ats_malloc(sizeof(struct dirent) + pathconf(".", _PC_NAME_MAX) + 1); + dirEntrySpace = (struct dirent *)ats_malloc(sizeof(struct dirent) + ink_file_namemax(".") + 1); while (readdir_r(dir, dirEntrySpace, &entryPtr) == 0) { if (!entryPtr) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/mgmt/MultiFile.cc ---------------------------------------------------------------------- diff --git a/mgmt/MultiFile.cc b/mgmt/MultiFile.cc index 3e0cdab..38c0bb2 100644 --- a/mgmt/MultiFile.cc +++ b/mgmt/MultiFile.cc @@ -113,7 +113,7 @@ MultiFile::WalkFiles(ExpandingArray * fileList) // The fun of Solaris - readdir_r requires a buffer passed into it // The man page says this obscene expression gives us the proper // size - dirEntry = (struct dirent *)ats_malloc(sizeof(struct dirent) + pathconf(".", _PC_NAME_MAX) + 1); + dirEntry = (struct dirent *)ats_malloc(sizeof(struct dirent) + ink_file_namemax(".") + 1); struct dirent *result; while (readdir_r(dir, dirEntry, &result) == 0) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/mgmt/Rollback.cc ---------------------------------------------------------------------- diff --git a/mgmt/Rollback.cc b/mgmt/Rollback.cc index b2e2be3..ca4cd90 100644 --- a/mgmt/Rollback.cc +++ b/mgmt/Rollback.cc @@ -668,7 +668,7 @@ Rollback::findVersions_ml(ExpandingArray * listNames) // The fun of Solaris - readdir_r requires a buffer passed into it // The man page says this obscene expression gives us the proper // size - dirEntrySpace = (struct dirent *)ats_malloc(sizeof(struct dirent) + pathconf(".", _PC_NAME_MAX) + 1); + dirEntrySpace = (struct dirent *)ats_malloc(sizeof(struct dirent) + ink_file_namemax(".") + 1); while (readdir_r(dir, dirEntrySpace, &entryPtr) == 0) { if (!entryPtr) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/mgmt/WebMgmtUtils.cc ---------------------------------------------------------------------- diff --git a/mgmt/WebMgmtUtils.cc b/mgmt/WebMgmtUtils.cc index df7f6e6..423c612 100644 --- a/mgmt/WebMgmtUtils.cc +++ b/mgmt/WebMgmtUtils.cc @@ -1305,7 +1305,7 @@ getFilesInDirectory(char *managedDir, ExpandingArray * fileList) // The fun of Solaris - readdir_r requires a buffer passed into it // The man page says this obscene expression gives us the proper // size - dirEntry = (struct dirent *)alloca(sizeof(struct dirent) + pathconf(".", _PC_NAME_MAX) + 1); + dirEntry = (struct dirent *)alloca(sizeof(struct dirent) + ink_file_namemax(".") + 1); struct dirent *result; while (readdir_r(dir, dirEntry, &result) == 0) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f2fc2890/proxy/logging/LogConfig.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogConfig.cc b/proxy/logging/LogConfig.cc index 5c07a81..4bb2bcf 100644 --- a/proxy/logging/LogConfig.cc +++ b/proxy/logging/LogConfig.cc @@ -1367,12 +1367,7 @@ LogConfig::update_space_used() } if (!m_dir_entry) { - long name_max = pathconf(logfile_dir, _PC_NAME_MAX); - - // pathconf should not fail after access and opendir have succeeded - // - ink_release_assert(name_max > 0); - + size_t name_max = ink_file_namemax(logfile_dir); m_dir_entry = (struct dirent *)ats_malloc(sizeof(struct dirent) + name_max + 1); }
